Input decimal numbers and find their sum and average in C++
cin - Question 2
In this question, we will see how to input 5 decimal numbers in C++ programming using the cin statement and find their sum and average. To know more about cin statement click on the cin statement lesson.
Q2) Write a program in C++ to input 5 decimal numbers and find their sum and average.
Program
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
float a,b,c,d,e,sum,avg;
cout<<"Enter 5 decimal numbers\n";
cin>>a>>b>>c>>d>>e;
sum=a+b+c+d+e;
avg=sum/5;
cout<<"Sum="<<sum<<endl;
cout<<"Average="<<avg;
return 0;
}
Output
Enter 5 decimal numbers 12.36 15.1 3.24 18.9 21.17 Sum=70.77 Average=14.154