exercise 1.30 solution

#include <iostream>

using std::cout;
using std::endl;
using std::cin;

int main() {
	int num1, num2, num3, num4, num5;

	cout << "Enter first integer: ";
	cin >> num1;

	cout << "\nEnter second integer: ";
	cin >> num2;

	cout << "\nEnter third integer: ";
	cin >> num3;

	cout << "\nEnter fourth integer: ";
	cin >> num4;

	cout << "\nEnter fifth integer: ";
	cin >> num5;

	int largest_num = num1;
	if(largest_num < num2) {
		largest_num = num2;
	}

	if(largest_num < num3) {
		largest_num = num3;
	}

	if(largest_num < num4) {
		largest_num = num4;
	}

	if(largest_num < num5) {
		largest_num = num5;
	}

	cout << "\nlargest number " << largest_num;

	int smallest_num = num1;
	if(smallest_num > num2) {
		smallest_num = num2;
	}

	if(smallest_num > num3) {
		smallest_num = num3;
	}

	if(smallest_num > num4) {
		smallest_num = num4;
	}

	if(smallest_num > num5) {
		smallest_num = num5;
	}

	cout << "\nsmallest number " << smallest_num << endl;

	return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s