Mega Code Archive

 
Categories / C / Language Basics
 

While to sum integers

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