-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06.cpp
More file actions
34 lines (27 loc) · 908 Bytes
/
06.cpp
File metadata and controls
34 lines (27 loc) · 908 Bytes
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
// C++ program to find the largest, smallest, and the second among three numbers.
#include <iostream>
using std::cin, std::cout;
int main()
{
// declaring the required variables.
int a, b, c, largest, secondLargest, smallest;
// entering the values for the variables from the console.
cout << "Enter three numbers: ";
cin >> a >> b >> c;
// finding the largest, smallest, and the second.
largest = a;
if(b > largest)
largest = b;
if(c > largest)
largest = c;
smallest = a;
if(b < smallest)
smallest = b;
if(c < smallest)
smallest = c;
secondLargest = (a + b + c) - (largest + smallest);
// printing the largest, smallest, and the second.
cout << "Smallest: " << smallest << "\n";
cout << "Second largest: " << secondLargest << "\n";
cout << "Largest: " << largest;
}