/*c program foe sum of first n natural numbers using while loop*/
#include<stdio.h>#include<conio.h>
void main()
{
int n,i,sum;
clrscr();
printf("Enter a number \n");
scanf("%d",&n);
i=1;
sum=0;
while(i<=n)
{
sum+=i;
i++;
}
printf("sum =%d\n",sum);
getch();
}
output
Enter a number10
sum=55
Comments
Post a Comment