Answer to Question #340332 in C++ for Nia

Question #340332

Write a program that inputs three integers from the keyboard and prints the sum,


average, product, smallest and largest of these numbers. The screen dialog should


appear as follows:


Input three different integers: 13 27 14


Sum is 54


Average is 18


Product is 4914


Smallest is 13


Largest is 27



1
Expert's answer
2022-05-12T08:21:31-0400
#include<iostream>


using namespace std;


int main()
{
	int arr[3];
	cout << "Please, enter three integers: ";
	for (int i = 0; i < 3; i++)
	{
		cin >>arr[i];
	}
	cout << "Sum is " << arr[0] + arr[1] + arr[2] <<endl;
	cout << "Average is " << (arr[0] + arr[1] + arr[2])/3 << endl;
	cout << "Product is " << arr[0] * arr[1] * arr[2] << endl;
	int smal = arr[0];
	int larg = arr[0];
	for (int i = 0; i < 3; i++)
	{
		if (arr[i] < smal)
			smal = arr[i];
		if (arr[i] > larg)
			larg = arr[i];
	}
	cout << "Smallest is " << smal << endl;
	cout << "Largest is " << larg << endl;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS