1
0

summing.c 550 B

123456789101112131415161718192021
  1. /* summing.c -- sums integers entered interactively */
  2. #include <stdio.h>
  3. int main(void)
  4. {
  5. long num;
  6. long sum = 0L; /* initialize sum to zero */
  7. int status;
  8. printf("Please enter an integer to be summed ");
  9. printf("(q to quit): ");
  10. status = scanf("%ld", &num);
  11. while (status == 1) /* == means "is equal to" */
  12. {
  13. sum = sum + num;
  14. printf("Please enter next integer (q to quit): ");
  15. status = scanf("%ld", &num);
  16. }
  17. printf("Those integers sum to %ld.\n", sum);
  18. return 0;
  19. }