Thursday, 27 February 2014

C# Programming

How to find the largest number from 3 numbers using c#?

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

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(FindLargestNo(6, 3, 9));
            Console.Read();
        }
        /// <summary>
        /// Find the largest of three numbers
        /// </summary>
        /// <param name="a">first parameter</param>
        /// <param name="b">second parameter</param>
        /// <param name="c">third parameter</param>
        /// <returns></returns>
        public static long FindLargestNo(long a, long b, long c)
        {
            //assume that the first value is biggest
            long biggest = a;

            //check if b is biggest
            if (b > biggest)
            {
                biggest = b;
            }

            //check if c is biggest
            if (c > biggest)
            {
                biggest = c;
            }
            return biggest;

        }
    }
}

Output:-9

No comments:

Post a Comment

Thanks for comments.