C Program to Calculate the Sum of Natural Numbers
#include<stdio.h>
int main()
{
int a,sum=0,i=0;
printf("Enter number:");
scanf("%d",&a);
while(i<=a)
{
sum=sum+i;
i++;
}
printf("%d",sum);
return 0;
}
|
Output:
Enter number:10
55
No comments:
Post a Comment