C# Program to Find largest of 3 numbers using Function overloading

C# Program to Find largest of 3 numbers using Function overloading

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication4
{
class CalculateMax
{
public int Largest(int number1, int number2, int number3)
{
if(number1>number2)
if(number1>number3)
{
return number1;
}
else
{
return number3;
}
else
{
if (number2>number3)
{
return number2;
}
else
{
return number3;
}
}
}

public float Largest(float number1, float number2, float number3)
{
if(number1>number2)
if(number1>number3)
{
return number1;
}
else
{
return number3;
}
else
{
if (number2>number3)
{
return number2;
}
else
{
return number3;
}
}
}

static void Main(string[] args)
{
int result1;
float result2;
CalculateMax d = new CalculateMax();
result1 = d.Largest(10, 20, 30);
result2 = d.Largest(10.1F, 20.1F, 30.1F);
Console.WriteLine(“The result of largest is: {0}”, result1);
Console.WriteLine(“The result of largest is: {0}”, result2);

Console.ReadLine();
}
}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication4
{
    class CalculateMax
    {
        public int Largest(int number1, int number2, int number3)
        {
            if(number1>number2)
            if(number1>number3)
            {
                return number1;
            }
            else
            {
                return number3;
            }
            else
            {
                if (number2>number3)
                {
                    return number2;
                }
                else
                {
                    return number3;
                }
            }
        }
                public float Largest(float number1, float number2, float number3)
                {
                    if(number1>number2)
            if(number1>number3)
            {
                return number1;
            }
            else
            {
                return number3;
            }
            else
            {
                if (number2>number3)
                {
                    return number2;
                }
                else
                {
                    return number3;
                }
            }
        }
               
        static void Main(string[] args)
        {
            int result1;
            float result2;
            CalculateMax d = new CalculateMax();
            result1 = d.Largest(10, 20, 30);
            result2 = d.Largest(10.1F, 20.1F, 30.1F);
            Console.WriteLine(“The result of largest is: {0}”, result1);
            Console.WriteLine(“The result of largest is: {0}”, result2);
     
            Console.ReadLine();
        }
    }
}

Add Comment