杭电ACM1092题目 Problem Description Your task is to Calculate the sum of some integers.Input Input
#include"stdio.h"
int main()
{
int a,b,n;
a=0;
while(scanf("%d",&n)!=EOF){
while(n--){
scanf("%d",&b);
a=a+b;
}
printf("%d\n",a);
}
return 0;
}
错在哪里啊啊,说的基础点的额
人气:387 ℃ 时间:2020-01-30 11:03:57
解答
1、你的a=0放的地方不对,你这样的话只有第一次的结果是对的.应该把它放到循环里面
2、题目要求的是N为0时结束,你的代码在N为0时还做了一次输出
3、虽然题目没说整数的范围,但是可能会因为int类型不够,加法会产生溢出#include"stdio.h"int main(){ int n,b=0,c; scanf("%d",&n)!=EOF; while((n--)!=0){scanf("%d",&c);b+=c; }printf("%d",b);return 0;}这个是不是之前的错误一样。。。可是造你说的改了不行么,,,可不可以帮我把这第二个改下正确,,,谢谢你这个代码主要是一个错误:题目说了会有多组测试(N会有多个),你的代码只输入了一次N就结束了 在你的代码基础上的话可以这样改吧#include"stdio.h"int main(){ int n,a,c; while(scanf("%d",&n),n) {a = 0;while((n--)!=0){scanf("%d",&c);a += c;}printf("%d\n",a);}return 0;} 测试过,Accepted
推荐
- show that,given any sequence of n integers,x1,x2,x3.xn some consecutive collection has a sum dividible by n
- 我的几个同学自愿演出工作.Some of my clasmates ______ _____ _____ some work for the show.
- Look!Some meat ___ in the box.Some peaches ___ in the plate.A is .are B are.are C are.is
- I can see some apples on the tree.(对画线部分提问)画线部分是some apples.
- 英语翻译
- 一筐水果连筐重48千克,取出一半后,连筐重25千克,这只筐里原来有水果多少千克?
- 甲、乙、丙3个数的比是3:4:5,这三个数的平均数是96,这3个数分别是多少?
- 正方形ABCD的边长为a,E 为AD的中点,BM⊥BC与M,则BM的长为_____ 等腰梯形两对对角线互相垂直,中位线长为
猜你喜欢