hd-1092:A+B for Input-Output Practice (IV)
2015-07-20 21:28
627 查看
[align=left]Problem Description[/align]
Your task is to Calculate the sum of some integers.
[align=left]Input[/align]
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.
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
4 1 2 3 4
5 1 2 3 4 5
0
[align=left]Sample Output[/align]
10
15 #include <stdio.h>
int main()
{
int n,i,a[100],sum;
while(scanf("%d",&n)&&(n!=0))
{
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0,sum=0;i<n;i++)
sum+=a[i];
printf("%d\n",sum);
}
return 0;
}
Your task is to Calculate the sum of some integers.
[align=left]Input[/align]
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.
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
4 1 2 3 4
5 1 2 3 4 5
0
[align=left]Sample Output[/align]
10
15 #include <stdio.h>
int main()
{
int n,i,a[100],sum;
while(scanf("%d",&n)&&(n!=0))
{
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0,sum=0;i<n;i++)
sum+=a[i];
printf("%d\n",sum);
}
return 0;
}
相关文章推荐
- hd-1091:A+B for Input-Output Practice (III)
- hd-1090:A+B for Input-Output Practice (II)
- hd-1089:A+B for Input-Output Practice (I)
- 开发笔记phpmailer
- php学习笔记8--半边引号引发的问题
- php
- yii2学习整理
- PHP多线程的实现
- 【php相关知识】如何生成一个库的php文档 ?
- yii2.0操作数据库
- 2015 PHP框架调查结果出炉,Laravel最受欢迎!
- php strftime()的使用
- Using CSV-Format Log Output
- LAMP服务器环境之编译(部分)安装-php的modules模式
- php数组排序(可升降序)
- (转)ThinkPHP使用心得分享-分页类Page的用法
- php -- 用文本来存储内容,file_put_contents,serialize,unserialize
- PHP自毁程序
- FLASH 结合PHP 实现文件上传
- php判断 获取字符串的编码类型