C++ Programs & Stuffz

Nothing like anything!!!

Please Click on ADS!!

Please Click on the above ads given by GOOGLE , so that I can maintain my blog!!

Tuesday, August 31, 2010

Find the sum and average of first n numbers

//pgm to find the sum and average of first n numbers
#include<iostream.h>
#include<conio.h>
void main()
{
    float i,n,sum,average;
    clrscr();
    cout<<"enter the value of n";
    cin>>n;
    sum=0;
    for(i=1;i<=n;i++)
        sum=sum+i;
    average=sum/n;
    cout<<"sum="<<sum<<endl;
    cout<<"average="<<average;
    getch();
}

0 comments:

Post a Comment

free counters