Sum integers with while loop - C Statement

C examples for Statement:while

Description

Sum integers with while loop

Demo Code

#include <stdio.h>

int main(void){
  int count, sum, max_count;
  sum = 0;/*from   w w w.  j av  a 2 s .c  om*/
  count = 1;

  printf("How many integers would you like to sum? ");
  scanf("%d", &max_count);

  while (count <= max_count){
    sum = sum + count;
    count++;
  }
  printf("sum = %d\n", sum);

  return 0;
}

Result


Related Tutorials