For and sum:Sum the integers from 1 to a user-specified number
#include <stdio.h>
void main() {
long sum = 0L;
int count = 10; /* The number of integers to be summed */
int i = 0; /* The loop counter */
/* Sum integers from 1 to count */
for(i = 1 ; i <= count ; i++)
sum += i;
printf("\nTotal of the first %d numbers is %ld\n", count, sum);
}
Related examples in the same category