杭电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;}错在哪里啊啊
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/24 03:39:04
杭电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;}错在哪里啊啊
杭电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;
}
错在哪里啊啊,说的基础点的额
杭电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;}错在哪里啊啊
1、你的a=0放的地方不对,你这样的话只有第一次的结果是对的.应该把它放到循环里面
2、题目要求的是N为0时结束,你的代码在N为0时还做了一次输出
3、虽然题目没说整数的范围,但是可能会因为int类型不够,加法会产生溢出