C# Program:To Find The Greatest Of 3 Numbers Entered By User

Sunday, 12 February 2012
using System;
class Greatest
{
        public static void Main()
       {
             int n1, n2, n3;
            Console.WriteLine("Enter Three no:");
            n1=Convert.ToInt32(Console.ReadLine());
            n2=Convert.ToInt32(Console.ReadLine());
            n3=Convert.ToInt32(Console.ReadLine());
           if(n1>n2)
                   if(n1>n3)
                 {
                     Console.WriteLine("The Greatest Of Three numbers are:"+n1);
                  }
                  else
                 {
                     Console.WriteLine("The Greatest Of Three numbers are:"+n3);
                  }
                  else
                  if(n2>n3)
                 {
                     Console.WriteLine("The Greatest Of Three numbers are:"+n2);
                 }
                else
                {
                     Console.WriteLine("The Greatest Of Three numbers are:"+n3 );
                }
          }

}

4 comments:

  1. Unknown said...:

    but what if n1=n2,,, then this program will give wrong output

  1. Anonymous said...:

    int a, b, c, d, e;
    a = Int32.Parse(Console.ReadLine());
    b = Int32.Parse(Console.ReadLine());
    c = Int32.Parse(Console.ReadLine());
    d = Int32.Parse(Console.ReadLine());
    e = Int32.Parse(Console.ReadLine());
    if (a > b && a > c && a > d && a > e)
    {
    Console.WriteLine("greater is: {0}", a);
    }
    if (b > a && b > c && b > d && b > e)
    {
    Console.WriteLine("greater is: {0}", b);
    }
    if (c > a && c > b && c > d && c > e)
    {
    Console.WriteLine("greater is: {0}", c);
    }
    if (d > a && d > b && d > c && d > e)
    {
    Console.WriteLine("greater is: {0}", d);
    }
    if (e > a && e > b && e > c && e > d)
    {
    Console.WriteLine("greater is: {0}", e);
    }

  1. gowsalya said...:

    This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
    AWS Training in pune
    AWS Online Training
    AWS Training in Bangalore

Post a Comment