Do a calculation within the third control expression in a for loop - C Statement

C examples for Statement:for

Description

Do a calculation within the third control expression in a for loop

Demo Code

#include <stdio.h>

int main(void)
{
  unsigned  long long sum = 0LL;            // Stores the sum of the integers
  unsigned int count = 0;                   // The number of integers to be summed

  printf("\nEnter the number of integers you want to sum: ");
  scanf(" %u", &count);

  for(unsigned int i = 1 ; i <= count ; sum += i++);

  printf("\nTotal of the first %u numbers is %llu\n", count, sum);
  return 0;/*from ww  w .j a v a2 s.c o m*/
}

Result


Related Tutorials