This C# program is to find the largest of the five numbers using else if statement. There are other things where people searching for largest of two numbers, largest of three numbers etc,. But here we have different aspect where we find the largest of five numbers.
First is to get the five numbers from the user or define in top section of the program. Console.ReadLine(). This method allow one to accept the input from the user and assign them into integer variable a, b, c, d, e. The logic of finding largest of five number is written in if statement and depending on that logic update big variable and at last display the big variable.
C# is an object oriented language so we create an object to call the class bigger which we have written our program. Call the class in main program as bigger s = new bigger() in this class we wrote a code inside the method so using "b" object call the method b.bigger(). Now the our c# program to find the largest of five number using else if statement program is ready run, if you get any difficulties then post a comment here.
First is to get the five numbers from the user or define in top section of the program. Console.ReadLine(). This method allow one to accept the input from the user and assign them into integer variable a, b, c, d, e. The logic of finding largest of five number is written in if statement and depending on that logic update big variable and at last display the big variable.
C# is an object oriented language so we create an object to call the class bigger which we have written our program. Call the class in main program as bigger s = new bigger() in this class we wrote a code inside the method so using "b" object call the method b.bigger(). Now the our c# program to find the largest of five number using else if statement program is ready run, if you get any difficulties then post a comment here.
Source code:-
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace big { class biggest { public void big() { int a, b, c, d, e, big; Console.WriteLine("ENTER ANY FIVE INTEGER NUMBERS"); a = int.Parse(Console.ReadLine()); b = int.Parse(Console.ReadLine()); c = int.Parse(Console.ReadLine()); d = int.Parse(Console.ReadLine()); e = int.Parse(Console.ReadLine()); if (a > b && a>c && a>d && a>e) { big = a; } else if (b > a && b > c && b > d && b > e) { big = b; } else if (c > b && c > a && c > d && c > e) { big = c; } else if (d > b && d > c && d > a && d > e) { big = d; } else { big = e; } Console.WriteLine("largest=" + big); Console.Read(); } } class Program { static void Main(string[] args) { biggest b = new biggest(); b.big(); } }
OUTPUT:-
ENTER ANY FIVE INTEGER NUMBER
666
777
444
555
222
largest = 777
No comments:
Write comments