Print Friendly and PDF
Arithmetic, Smallest and Largest) 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
Arithmetic, Smallest and Largest) 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

Solution: 

 
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
 
int main()
{
  int x, y, z;
   int sum, average, product, smallest, largest;
 
  cout << "Input three different integers: ";
  cin  >> x >> y >> z;
 
   sum = x + y + z;
  average = (x + y + z)/3;
  product = x * y * z;
 
   cout << "Sum is " << sum << endl;
   cout << "Average is " << average << endl;
   cout << "Product is " << product << endl;
 
   if ((x<y)&&(x<z))
     cout << "Smallest is " << x << endl;
   if ((y<x)&&(y<z))
     cout << "Smallest is " << y << endl;
   if ((z<x)&&(z<y))
     cout << "Smallest is " << z << endl;
   if ((x>y)&&(x>z))
     cout << "Largest is " << x << endl;
   if ((x<y)&&(z<y))
     cout << "Largest is " << y << endl;
   if ((z>y)&&(z>x))
     cout << "Largest is " << z << endl;
 
   return 0;
}
 
zubairsaif

Zubair saif

A passionate writer who loves to write on new technology and programming

Post A Comment:

0 comments: