Mega Code Archive

 
Categories / C / Code Snippets
 

While to sum integers

#include <stdio.h> void main() { long sum = 0L; int x = 1; /* Indexes through the integers */ int count = 10; /* The count of integers to be summed */ /* Sum the integers from 1 to count */ while(x <= count) sum += x++; printf("Total of the first %d numbers is %ld\n", count, sum); }