exercise 1.26 solution

#include <iostream>

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

int main() {
	// store user input
	int num1, num2, num3;

	// prompt the user to enter 3 integer
	cout << "Input three different integers: ";
	cin >> num1 >> num2 >> num3;
	
	int sum = num1 + num2 + num3;
	int average = (num1 + num2 + num3) / 3;
	int product = num1 * num2 * num3;
	int largest;	

	if(num1 > average)
		largest = num1;
	else if(num2 > average)
		largest = num2;
	else
		largest = num3;

	int smallest;
	int median = (sum - largest) / 2;
	if(num1 < median)
		smallest = num1;
	else if(num2 < median)
		smallest = num2;
	else
		smallest = num3;

	cout << "Sum is " << sum << endl;
	cout << "Average is " << average << endl;
	cout << "Product is " << product << endl; 	
	cout << "Smallest is " << smallest << endl;		
	cout << "Largest is " << largest << 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