搜索
编程论坛
→
开发语言
→
『 C语言论坛 』
→ unsigned与long int的问题!
标题:
unsigned与long int的问题!
取消只看楼主
守望麦田
等 级:
新手上路
帖 子:23
专家分:0
注 册:2012-12-26
结帖率:
83.33%
楼主
已结贴
√
问题点数:10 回复次数:3
unsigned与long int的问题!
一个求1到n的和的题:
我代码如下:
#include<iostream>
using namespace std;
int main()
{
unsigned int n;//为什么用long就不行了?
while(cin>>n)
{
cout<<(1+n)*n/2<<endl<<endl;
}
return 0;
}
代码第五行把unsigned换成long为何就不行了?
搜索更多相关主题的帖子:
long
2013-03-19 19:49
守望麦田
等 级:
新手上路
帖 子:23
专家分:0
注 册:2012-12-26
第
2
楼
得分:0
哥们!有想法的就发表下咯!
2013-03-19 20:36
守望麦田
等 级:
新手上路
帖 子:23
专家分:0
注 册:2012-12-26
第
3
楼
得分:0
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.
Sample Input
1
100
Sample Output
1
5050
原题是这样的!
2013-03-19 20:38
守望麦田
等 级:
新手上路
帖 子:23
专家分:0
注 册:2012-12-26
第
4
楼
得分:0
我也觉得呗!
2013-03-19 20:46
4
1/1页
1
参与讨论请移步原网站贴子:
https://bbs.bccn.net/thread-401305-1-1.html
关于我们
|
广告合作
|
编程中国
|
清除Cookies
|
TOP
|
手机版
编程中国
版权所有,并保留所有权利。
Powered by
Discuz
, Processed in 0.306591 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved