[C] addn.c -- Read a positive number N. Then read N in →→→→→进入此内容的聊天室

来自 Bistre Hedgehog, 2022-06-20, 写在 C, 查看 98 次.
URL http://www.code666.cn/view/fd5daa53
  1. /* addn.c -- Read a positive number N. Then read N integers and
  2.  *           print them out together with their sum.
  3.  */
  4.  
  5. #include <stdio.h>
  6.  
  7. int main(void) {
  8.   int n;       /* The number of numbers to be read */
  9.   int sum;     /* The sum of numbers already read  */
  10.   int current; /* The number just read             */
  11.   int lcv;     /* Loop control variable, it counts the number
  12.                   of numbers already read */
  13.  
  14.   printf("Enter a positive number n > ");
  15.   scanf("%d",&n); /* We should check that n is really positive*/
  16.   sum = 0;
  17.   for (lcv=0; lcv < n; lcv++) {
  18.     printf("\nEnter an integer > ");
  19.     scanf("%d",&current);
  20.     /*    printf("\nThe number was %d\n", current); */
  21.     sum = sum + current;
  22.   }
  23.   printf("The sum is %d\n", sum);
  24.   return 0;
  25. }

回复 "addn.c -- Read a positive number N. Then read N in"

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

captcha