A+B for Input-Output Practice (IV)
2020-03-30 07:34
1211 查看
Problem Description
Your task is to Calculate the sum of some integers.
Input
Input contains multiple test cases. Each test case contains a integer N, and then N integers follow in the same line. A test case starting with 0 terminates the input and this test case is not to be processed.
Output
For each group of input integers you should output their sum in one line, and with one line of output for each line in input.
Sample Input
4 1 2 3 4
5 1 2 3 4 5
0
Sample Output
10
15
C
#include <stdio.h> #pragma warning(disable:4996) int main(void) { int sum,input,i,n; while(scanf("%d",&n)&&n) { for(i=0,sum=0;i<n;i++) { scanf("%d",&input); sum+=input; } printf("%d\n",sum); } return 0; }
每行第一个数字表示接下来要给的数字数量,写在while循环里。
然后for循环读入剩余的数字并相加,for循环结束后输出和。
注意:
C语言用除0以外的任何数表示真,所以在n=0时,while循环结束。
每次计算后要把sum的值归0。
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- Hdoj 1092 A+B for Input-Output Practice (IV)
- SDUT 1013 A+B for Input-Output Practice (IV)
- A+B for Input-Output Practice (IV)
- Java数组实例-A+B for Input-Output Practice (IV) A + B
- A+B for Input-Output Practice (IV)
- HDOJ 1092 A+B for Input-Output Practice (IV)
- A+B for Input-Output Practice (IV)
- A+B for Input-Output Practice (IV)
- 杭电 HDU 1092 A+B for Input-Output Practice (IV)
- A+B for Input-Output Practice (IV)
- A+B for Input-Output Practice (IV)
- A+B for Input-Output Practice (IV)
- HDU 1.1.4 A+B for Input-Output Practice (IV)
- hdoj A+B for Input-Output Practice (IV)
- HDOJ 1092 A+B for Input-Output Practice (IV)
- HDOJ 1092:A+B for Input-Output Practice (IV)
- [水题][hdoj_1092]A+B for Input-Output Practice (IV)
- HDOJ 1091 A+B for Input-Output Practice (IV)
- 1092 A+B for Input-Output Practice (IV)
- 「HD_ACM」A+B for Input-Output Practice (IV)