Mega Code Archive

 
Categories / C Tutorial / Data Type
 

Sum the integers from 1 to a user-specified number

#include <stdio.h> int main(void) {   long sum = 0L;   int count = 100;   for(int i = 1 ; i <= count ; i++){     sum += i;   }     printf("\nTotal of the first %d numbers is %ld\n", count, sum);   return 0; } Total of the first 100 numbers is 5050