Cpp Simple Program For Finding Average

Finding average is one of the simplest programs. Here we input 5 variables, then added together for ‘sum’ and the ‘sum’ is divided by the 5 to produce the average.


The Program



//program to find average.
#include<iostream.h>
#include<conio.h>
void main()
{
int i,x,sum=0,avg;
clrscr();
cout<<"Enter the 5 elements\n";
for(i=0;i<5;i++)
                {
                cin>>x;
                sum=sum+x;
                }
avg=sum/5;
cout<<"sum="<<sum;
cout<<"avg="<<avg;
getch();

}

Run the program after compilation. If any problems: post at here...

Popular posts from this blog

How to pass variables to res.render() in Node.js

Talky Messenger Documentation & Setup