[C] add.c -- Read a sequence of positive integers and →→→→→进入此内容的聊天室

来自 Abrupt Marten, 2022-06-20, 写在 C, 查看 77 次.
URL http://www.code666.cn/view/95630a9f
  1. /* add.c -- Read a sequence of positive integers and print them
  2.  *          out together with their sum. Use a Sentinel value
  3.  *          (say 0) to determine when the sequence has terminated.
  4.  */
  5.  
  6. #include <stdio.h>
  7. #define SENTINEL 0
  8.  
  9. int main(void) {
  10.   int sum = 0; /* The sum of numbers already read */
  11.   int current; /* The number just read */
  12.  
  13.   do {
  14.     printf("\nEnter an integer > ");
  15.     scanf("%d", &current);
  16.     if (current > SENTINEL)
  17.       sum = sum + current;
  18.   } while (current > SENTINEL);
  19.   printf("\nThe sum is %d\n", sum);
  20. }

回复 "add.c -- Read a sequence of positive integers and "

这儿你可以回复上面这条便签

captcha