find largest and smallest number in c 2b 2b

Solutions on MaxInterview for find largest and smallest number in c 2b 2b by the best coders in the world

showing results for - "find largest and smallest number in c 2b 2b"
Gertrude
01 Mar 2017
1#include <iostream>
2using namespace std;
3
4int main()
5{
6	int again, num, smallest = 0, largest = 0;
7	
8	cout << "Enter a positive number (program will execute at \"0\"): ";
9	
10	do
11	{
12		cin >> num;
13		if (num < 0)
14		{
15			cout << "Wrong Attempt! You have entered a negative number" << endl;
16			cout << "Enter a positive number: ";
17		}
18		if (num <= smallest)
19			smallest = num;
20		if (num >= largest)
21			largest = num;
22	} while (num != 0);
23	cout << "Smallest number: " << smallest << endl;
24	cout << "Largest number: " << largest << endl;
25
26	return 0;
27}