S1006 scanf()可以全部输入数字再点击,程序自动执行

来源:互联网 发布:淘宝手机端红包设置 编辑:程序博客网 时间:2024/06/09 20:58

Description

Your task is to calculate the sum of some integers.

Input

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.
It is guarantied that all integers and the sum are in the range of 32-int.

Output

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.

Sample Input

4 1 2 3 45 1 2 3 4 5

Sample Output

1015

一,正确方法

# include <stdio.h>   int main() {  int N,a,sum;   while(scanf("%d",&N)!=EOF)  {sum = 0;while(N){scanf("%d",&a);sum += a;N--;}printf("%d\n",sum);}return 0;  }
二,收获体会

这里的scanf可以全部输入数字再点击,即点击一个回车,同时把scanf()赋给N多个a,并且程序自动执行。




阅读全文
0 0
原创粉丝点击