Saturday, February 14, 2015

C Program to find sum of first n natural number


#include<iostream.h>
#include<conio.h>
void main()
{       clrscr();
int i,n,sum=0;
cout<<"How many numbers? ";
cin>>n;
for(i=1;i<=n;++i)
{
sum+=i;
cout<<"
SUM="<<sum<<endl;
}
getch();
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.