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
#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;
}
Comments
Leave a comment