Sum the integers from 1 to a user-specified number : int Calculation « Data Type « C Tutorial






#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








2.5.int Calculation
2.5.1.Simple calculations
2.5.2.Divide Integer
2.5.3.Sum the integers from 1 to a user-specified number
2.5.4.If both operands i1 and i2 are integers, the expression i1/i2 provides integer division