Sum of first N natural numbers in C.
#include <stdio.h>
#include <conio.h>
void main()
{
int n, i, sum = 0;
printf("Enter a positive integer: ");
scanf("%d", &n);
for (i = 1; i <= n; ++i) {
sum += i;
}
printf("Sum = %d", sum);
getch();
}
Expected Output:
Enter a positive integer:
100
Sum = 5050