Friday 23 January 2015

C# Program to find the largest among three numbers - Using If Else

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter the a,b and c value");
            int a, b, c;
            a = Convert.ToInt32(Console.ReadLine());
            //or
            // a = int.Parse(Console.ReadLine());
            b = Convert.ToInt32(Console.ReadLine());
            c = Convert.ToInt32(Console.ReadLine());
            if (a > b)
            {
                if (a == c)
                {
                Console.WriteLine("A and c are greatest and are equal");
                }
                else if (a > c)
                {
                    Console.WriteLine("A is bigger: {0}", a);
                }
                else
                {
                    Console.WriteLine("C is bigger: {0}", c);
                }

            }
            //
            else if (b > c)
            {
                if (b == a)
                {
                    Console.WriteLine("A and B is greater and Equal");
                }
                else if (b > a)
                {
                    Console.WriteLine("B is bigger: {0}", b);
                }
                else
                {
                    Console.WriteLine("A is bigger: {0}", a);
                }

            }
            //
            else if (a > c)
            {

                if (a > b)
                {
                    Console.WriteLine("A is bigger: {0}", a);
                }
                else
                {
                    Console.WriteLine("B is bigger: {0}", b);
                }                             
            }
             else if (c > a)
            {
                {
                 Console.WriteLine("c is bigger: {0}", c);
                }
               
             }
            else if (b > a)
            {
                {
                  Console.WriteLine("B is bigger: {0}", b);
                }

            }
           
              
                else if (b == c)
                {
                    if (b == a)
                    {
          Console.WriteLine("A , B , C is equal the value is:{0}", a);
                    }
                    else
                    {
          Console.WriteLine("B , C  is greatest and are equal ");
                    }

                }
                else if (c == a)
                {
                    if (c == b)
                    {
          Console.WriteLine("A , B , C is equal the value is:{0}", a);
                    }
                    else
                    {
         Console.WriteLine("A , C  is equal: {0}",c);
                    }

                }                              
         Console.ReadLine();
        }
    }

    }




No comments:

Post a Comment