Ads 468x60px

Labels

Jun 7, 2012

#6 - Sum Of N Natural Numbers [C]

#include"stdio.h"
#include"math.h"
void main()
{
int i,n,sum=0;
clrscr();
printf("\n Enter the value for N \n");
scanf("%d",&n);
i=0;
while(i<=n)
{
sum=sum+i;
i=i+1;
}
printf("The sum is %d",sum);
getch();
}

No comments:

Post a Comment