hd-1094:A+B for Input-Output Practice (VI)
2015-07-22 11:39
686 查看
[align=left]Problem Description[/align]
Your task is to calculate the sum of some integers.
[align=left]Input[/align]
Input contains multiple test cases, and one case one line. Each case starts with an integer N, and then N integers follow in the same line.
[align=left]Output[/align]
For each test case you should output the sum of N integers 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
[align=left]Sample Output[/align]
10
15 #include <stdio.h>
int main()
{
int n,i,a[1000],sum;
while(scanf("%d",&n)!=EOF)
{
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, and one case one line. Each case starts with an integer N, and then N integers follow in the same line.
[align=left]Output[/align]
For each test case you should output the sum of N integers 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
[align=left]Sample Output[/align]
10
15 #include <stdio.h>
int main()
{
int n,i,a[1000],sum;
while(scanf("%d",&n)!=EOF)
{
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-1093:A+B for Input-Output Practice (V)
- php学习笔记
- FTPClient上传和下载文件,中文乱码问题解决
- 使用PHP生成二维码的方法汇总
- TP的一些用法
- php翻页
- 理解钩子Hook以及在Thinkphp下利用钩子使用行为扩展
- 如何在win7中提供ftp服务
- Yii框架 多表查询实例
- php 数组排序
- php基础
- Windows 7中无法访问FTP的解决方法
- ThinkPHP验证码类
- PHP运行模式
- ThinkPHP验证码刷新随机数
- ZendFramework2学习笔记 json和ajax
- 项目开发经常使用PHP功能
- php基础
- js验证和PHP验证用户输入的区别
- php中mysql语句中如果有变量,该如何连接字符串