Mega Code Archive

 
Categories / C Tutorial / Statement
 

Sum integers in for statement

#include <stdio.h> int main(void) {   long sum = 0L;   int count = 0;      printf("\nEnter the number of integers you want to sum: ");   scanf(" %d", &count);      for (int i = 1 ; i<= count ; sum += i++ );   printf("\nTotal of the first %d numbers is %ld\n", count, sum);   return 0; } Enter the number of integers you want to sum: 112 Total of the first 112 numbers is 6328