acm_step1.1.4
来源:互联网 发布:淘宝男士家居服 编辑:程序博客网 时间:2024/05/20 08:23
题目描述:
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
题意:输入N,表示将要计算n个数的和,若n为0,则不作任何处理。
#include<stdio.h>int main(){ int n, a, i; int sum = 0; while (scanf("%d", &n) != EOF) { if (n != 0) { for (i = 0; i < n; i++) /*从0开始输入n个数*/ { scanf("%d", &a); sum += a; /*每次输入后都把值加到sum上*/ } printf("%d\n", sum); sum = 0; /*每次结束后都把sum重置为0*/ } } return 0;}
难点:对i从0到n-1时的处理,不太容易计算每次输入的和,容易忽略每次加后,对sum置0.
阅读全文
0 0
- acm_step1.1.4
- acm_step1.1.5
- 杭电ACM_step1.2.1
- 杭电acm_step1.2.2
- 杭电OJ acm_step1.1.2
- acm_step1.1.6 1.1.7 1.1.8
- 1.4
- 1.4
- 1.4
- 1.4
- 1.4
- 1.4
- 1.4
- 1.4
- 1.4
- 1.4
- 1.4. 安全问题
- 1.4 容器
- Linux下的系统编程总结
- 23. 单词接龙
- Android 实现左滑出现删除选项
- apk的打包过程
- GOP, scenecut 和 keyframe详解 [场景编码]
- acm_step1.1.4
- linux之信号量
- 24. 走迷宫
- 三层架构
- SSH的Maven整合POM
- javascript改变元素样式
- 06、react之 非DOM(元素)属性
- 25. 赶飞机
- myeclipse10创建maven web项目