杭电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-10-17 广告
2024-10-17 广告
ZigBee作为一项新型的无线通信技术,其具有传统网络通信技术所不可比拟的优势,既能够实现近距离操作,又可降低能源的消耗。又如,相较于蓝牙等无线通信技术,ZigBee无线通信技术可有效降低使用成本, 即便数据处理的速率并不高,然而,值得肯定...
点击进入详情页
本回答由晓网科技提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询