Greatest of three numbers Learn programming C#


Flow Control


Greatest of three numbers


Write a C# program that prompts the user to enter three numbers and displays the greatest one.


using System;
public class exercise19
  public static void Main()
   int number1, number2, number3;

   Console.Write("Enter the number 1:");
   number1 = Convert.ToInt32(Console.ReadLine());

   Console.Write("Enter the number 2:");
   number2 = Convert.ToInt32(Console.ReadLine());

   Console.Write("Enter the number 3:");
   number3 = Convert.ToInt32(Console.ReadLine());

   if ( number1 > number2 && number1 > number3)
    Console.WriteLine("The number 1 is greatest");
   else if ( number2 > number1 && number2 > number3)
    Console.WriteLine("The number 2 is greatest");
   else if ( number3 > number1 && number3 > number2)
    Console.WriteLine("The number 3 is greatest");
    Console.WriteLine("Numbers equals");

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.