Write a program to identify the largest of three numbers entered by a user. Create this program by using methods.
Sample Solution
C# Sharp Codeusing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Enter_5_Number { class Number { static int n1, n2, n3; public static void Greater() { if (n1 > n2 && n1 > n3) { Console.WriteLine("The Greatest Of Three numbers are:" + n1); } else if (n2 > n1 && n2 > n3) { Console.WriteLine("The Greatest Of Three numbers are:" + n2); } else { Console.WriteLine("The Greatest Of Three numbers are:" + n3); } } static void Main(string[] args) { Console.WriteLine("Enter Three no:"); n1 = Convert.ToInt32(Console.ReadLine()); n2 = Convert.ToInt32(Console.ReadLine()); n3 = Convert.ToInt32(Console.ReadLine()); Greater(); Console.ReadLine(); } } }
Sample Output
No comments:
Post a Comment