#include<stdio.h>intmain()
{
int n, i, sum = 0;
printf("Enter a positive integer: ");
scanf("%d",&n);
for(i=1; i <= n; ++i)
{
sum += i; // sum = sum+i;
}
printf("Sum = %d",sum);
return 0;
}
Sum of Natural Numbers
Reviewed by Unknown
on
01:56
Rating: 5
No comments: