Find average of number in C++ by R4R Team

Task:
Find the average of the given set of numbers.

Example-
numbers are: 1,2,3,4,5
average is: 3

program:

#include< iostream.h>
int main()
{
int a,b,c;
float avg;
cout<<"Enter first number"<< endl;
cin>>a;
cout<<"Enter second number"<< endl;
cin>>b;
cout<<"Enter third number"<< endl;
cin>>c;
avg=(a+b+c)/3;
cout<<"Average is "<< avg;
}


output-

Enter first number
3
Enter second number
2
Enter third number
1
Average is 2.000000

-In this program,we take an input of three integer number, and store their average in float variable because average may be of floating type.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!