-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlargest no.cpp
More file actions
61 lines (53 loc) · 1.36 KB
/
largest no.cpp
File metadata and controls
61 lines (53 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//Write a Program to read the number and to display the largest number among them
#include <iostream>
using namespace std;
//Largest between two nums
int twoNum()
{
int a,b;
cout<<"\nEnter two numbers:";
cin >> a >> b;
int ans = a>b?a:b;
cout << "\nThe largest between two nums is:"<< ans;
return 0;
}
//Largest between three nums
int threeNum()
{
int a,b,c;
cout<<"\nEnter three numbers:";
cin >> a >> b >> c;
int ans = (a>b && a>c)?a:(b>c)?b:c;
cout << "\nThe largest between three nums is:"<< ans;
return 0;
}
//Largest between four nums
int fourNum()
{
int a,b,c,d;
cout<<"\nEnter four numbers:";
cin >> a >> b >> c >> d;
int ans = (a>b && a>c && a>d)?a:(b>c && b>d)?b:(c>d)?c:d;
cout << "\nThe largest between four nums is:"<< ans;
return 0;
}
int main()
{
int choice;
cout <<"\n1.To display largest numbers between two numbers:";
cout <<"\n2.To display largest numbers between three numbers:";
cout <<"\n3.To display largest numbers between four numbers:";
cout << "\nPlease select from the options: ";
cin >> choice;
switch (choice)
{
case 1: twoNum();
break;
case 2: threeNum();
break;
case 3: fourNum();
break;
default: cout << "\n Invalid option entered.";
}
return 0;
}