求反序数

CUG_JaySun CUG_JaySun 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
这段代码可以执行,但是为什么输入10位数以上就出现错误?

#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main()
{ //数字逆序 //位数
int digits = 1;
int testDig = 0;
cin>>testDig;
int tmp = testDig;
if(abs(testDig) > 10)
{
while(abs(tmp) > 10)
{
tmp = abs(tmp) / 10;
digits++;
}
}
cout<<digits<<endl;
//逆序输出
tmp = testDig;
for(int cycle = 0; cycle <= digits; ++cycle)
{
cout<<abs(tmp) %10;
tmp = abs(tmp) / 10;
}
if(testDig < 0)
{
cout<<"-"<<endl;
}

//system("pause");
return 0;
}
...全文
评论 2
收藏 已收藏
分享
返回顶部
CUG_JaySun
C++ 语言 65,214 成员 250,514 内容