Chapter 4:
Input And Output
Programming Exercise
Problem # 5:
Write a program that inputs 4 numbers and calculates the sum, average, and product of all the numbers.
Solution:
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int n1, n2, n3, n4, sum, product;
float average;
cout<<"Enter 4 numbers: ";
cin>>n1>>n2>>n3>>n4;
sum=n1+n2+n3+n4;
average=sum/4.0;
product=n1*n2*n3*n4;
cout<<"Sum : "<<sum<<endl;
cout<<"Average : "<<average<<endl;
cout<<"Product : "<<product<<endl;
return 0;
}
#include<conio.h>
using namespace std;
int main()
{
int n1, n2, n3, n4, sum, product;
float average;
cout<<"Enter 4 numbers: ";
cin>>n1>>n2>>n3>>n4;
sum=n1+n2+n3+n4;
average=sum/4.0;
product=n1*n2*n3*n4;
cout<<"Sum : "<<sum<<endl;
cout<<"Average : "<<average<<endl;
cout<<"Product : "<<product<<endl;
return 0;
}
Code Screenshot:
Output:
Let me know in the comment section if you have any question.
Previous Post:
4. Program that inputs miles from the user and convert miles into kilometers.
Comments
Post a Comment