My photo
Bangalore, Karnataka, India
Extending one hand to help someone has more value rather than joining two hands for prayer

Archives

average of n numbers

Tuesday, September 1, 2009

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int x[50],i,n,sum=0;
float avg;
cout<<"value of n=";
cin>>n;
cout<<"enter the elements:";
for(i=0;i<n;i++)
{
 cin>>x[i];
 }
for(i=0;i<n;i++)
{
 cout<<"x["<<i<<"]="<<x[i]<<endl;
 sum=sum+x[i];
 }
 cout<<"avg=";
 avg=sum/n;
 cout<<avg;
 getch();
}

0 comments: