1006: A+B for Input-Output Practice (VI)

冷不防 2023-01-10 01:21 183阅读 0赞

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.

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.

" class="reference-link">Sample Input 5f8f312f51791b8bb0ed0ae07c2ffa43.gif

  1. 4 1 2 3 4
  2. 5 1 2 3 4 5

Sample Output

  1. 10
  2. 15

Code

  1. #include<stdio.h>
  2. #include<iostream>
  3. using namespace std;
  4. int main()
  5. {
  6. int a;
  7. while(~scanf("%d",&a))
  8. {
  9. int ans=0;
  10. int s[a];
  11. while(a--)
  12. {
  13. cin>>s[a];
  14. ans+=s[a];
  15. }
  16. cout<<ans<<endl;
  17. }
  18. return 0;
  19. }

发表评论

表情:
评论列表 (有 0 条评论,183人围观)

还没有评论,来说两句吧...

相关阅读