杭电ACm,problem1001的疑问,为什么不能用高斯算法
InputTheinputwillconsistofaseriesofintegersn,oneintegerperline.OutputForeachcase,outp...
Input
The input will consist of a series of integers n, one integer per line.
Output
For each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.
很疑惑
#include <iostream>
using namespace std;
void main()
{int n;
while(cin>>n)
{
int i,sum=0;
for(i=1;i<=n;i++) sum=sum+i;
cout<<sum<<endl<<endl;
}
}
成功ac但是
#include <iostream>
using namespace std;
void main()
{int n;
while(cin>>n)
{
cout<<n*(n+1)/2<<endl<<endl;
}
}
就老是报错,求教是为何,按照道理结果是一样的啊。 展开
The input will consist of a series of integers n, one integer per line.
Output
For each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.
很疑惑
#include <iostream>
using namespace std;
void main()
{int n;
while(cin>>n)
{
int i,sum=0;
for(i=1;i<=n;i++) sum=sum+i;
cout<<sum<<endl<<endl;
}
}
成功ac但是
#include <iostream>
using namespace std;
void main()
{int n;
while(cin>>n)
{
cout<<n*(n+1)/2<<endl<<endl;
}
}
就老是报错,求教是为何,按照道理结果是一样的啊。 展开
1个回答
富港检测技术(东莞)有限公司_
2024-05-27 广告
2024-05-27 广告
ISTA3E程序是对相同产品的集合包装的综合模拟性能测试,集合包装件被定义为将一个产品、多个产品或包装件放置在滑板或托盘上,固定在一起或是作为一个单元运输。例如:一台机器由带瓦楞底托的托盘上、瓦楞侧围、顶盖包装,用缠绕膜缠绕在托盘上。用于评...
点击进入详情页
本回答由富港检测技术(东莞)有限公司_提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询