-->

Thursday, February 27, 2014

c# programming : How to find largest number in given two number

c# programming : How to find largest number in given two number

You can easily find largest number between two number using Max, which is static method of Math class. This method is overload with multiple data types, such as Max(Byte, Byte) , Max(Decimal, Decimal) and many more data types. Here we take an example with integer number.

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = -3, b = 52;
            Decimal deci = -4, deci1 = 53;

            Console.WriteLine(" the maximum number in between a= {0} and b={1} are {2}",a,b, Math.Max(a, b));

            Console.WriteLine(" the maximum number in between a= {0} and b={1} are {2}", deci, deci1, Math.Max(deci, deci1));

            Console.ReadKey();

        }
    }
}

Code generate the following output

c# programming : How to find largest number in given two number

Read other related articles

Also read other articles

© Copyright 2013 Computer Programming | All Right Reserved