杭电ACM1092题目 Problem Description Your task is to Calculate th
来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/05/10 20:44:44
杭电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;
}
错在哪里啊啊,说的基础点的额
#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类型不够,加法会产生溢出
再问: #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
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
杭电ACM1092题目 Problem Description Your task is to Calculate th
Your task is to Calculate a + b.
Given an integer N(0 ≤ N ≤ 1000),your task is to calculate
C语言的简易编程问题Your task is to Calculate the sum of some integers
Your task is to find out the cost by bus Your task is findin
Problem Description
your task is to find out the cost by
Your task is to change words so that the sentence__________.
一个英语对话的题目A.What is your problem You seem to have been thinki
杭电acm 2034wrong answer Problem Description参加过上个月月赛的同学一定还记得其中
杭电acm2026 Problem Description输入一个英文句子,将每个单词的第一个字母改成大写字母.Inpu
I have a writing task.It is to make a short stroy.No more th