5. Program that inputs 4 numbers and calculates the sum, average, and product of all the numbers.

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;
}

Code Screenshot:

Chapter 4, Coding tutorial, Computer Science, CPP Basics, Exercise Solution, Input and Output, IT Series, Object Oriented Programming using C++, Programming for beginners, Programming Tutorial

 Output:

Chapter 4, Coding tutorial, Computer Science, CPP Basics, Exercise Solution, Input and Output, IT Series, Object Oriented Programming using C++, Programming for beginners, Programming Tutorial

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