Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int n, i=1, sum=0;
clrscr();
printf("Enter a Number : ");
scanf("%d", &n);
while(i<=n)
{
sum= sum + i;
i++;
}
printf("Sum of Natural Numbers from 1 to %d is : %d", n, sum);
getch();
}
Output:
Enter a Number : 10
Sum of Natural Numbers from 1 to 10 is : 55
Next Topic :
Previous Topic :
No comments:
Post a Comment