系统粉 > 电脑问答 > 其他问答

已解决哪位好心帮我用C++编写一个小程序,谢谢帮忙先

提问者:福清哥走天下  |  浏览次  |  提问时间:2017-01-11  |  回答数量:3

哪位好心帮我用C++编写一个小程序,谢谢帮忙先 如题:给出一个不多于5位的正整数,要求:1,求出它是几位数;2,分别打印出每一位数字;3,按逆序打印出各位数字,例如原数为321,应输出123.

已有3条答案
_沈柒墨

_沈柒墨

回答数:45  |  被采纳数:45

char str[10];
scanf("%s",str);
printf("%d位数",strlen(str));
printf(str);
int i=strlen(str)-1;
while(i>=0)printf("%c",str[i--]);
2017-01-11 01:21:58
赞 4
惟爱姜宝

惟爱姜宝

回答数:0  |  被采纳数:0

谢谢啦,不过我现在学C++的,C不太懂,有没有C++的?
2017-01-11 03:21:03
赞 0
weiyun510

weiyun510

回答数:34  |  被采纳数:118

#include<iostream>
using namespace std;
int main()
{
int num,place,i,j,k,m,n;
cout<<"请输入\n";
cin>>num;
if(num>99999)
cout<<"The data error! ";
else
if(num>9999)
{i=num/10000;
j=(num-i*10000)/1000;
k=(num-i*10000-j*1000)/100;
m=(num-i*10000-j*1000-k*100)/10;
n=num-i*10000-j*1000-k*100-m*10;
place=5;
cout<<"你输入数位数为:"<<place<<"\n";
cout<<"你输入数的各位为:\n";
cout<<i<<" "<<j<<" "<<k<<" "<<m<<" "<<n;
cout<<"\n";
cout<<"逆序排列为:\n";
cout<<n<<m<<k<<j<<i<<"\n";}
else
if(num>999)
{i=num/1000;
j=(num-i*1000)/100;
k=(num-i*1000-j*100)/10;
m=num-i*1000-j*100-k*10;
place=4;
cout<<"你输入数位数为:"<<place<<"\n";
cout<<"你输入数的各位为:\n";
cout<<i<<" "<<j<<" "<<k<<" "<<m;
cout<<"\n";
cout<<"逆序排列为:\n";
cout<<m<<k<<j<<i<<"\n";}
else
if(num>99)
{i=num/100;
j=(num-i*100)/10;
k=(num-i*100-j*10);
place=3;
cout<<"你输入数位数为:"<<place<<"\n";
cout<<"你输入数的各位为:\n";
cout<<i<<" "<<j<<" "<<k;
cout<<"\n";
cout<<"逆序排列为:\n";
cout<<k<<j<<i<<"\n";}
else
if(num>9)
{i=num/10;
j=num-i*10;
place=2;
cout<<"你输入数位数为:"<<place<<"\n";
cout<<"你输入数的各位为:\n";
cout<<i<<" "<<j;
cout<<"\n";
cout<<"逆序排列为:\n";
cout<<j<<i<<"\n";}
else
{i=num;
place=1;
cout<<"你输入数位数为:"<<place<<"\n";
cout<<"你输入数的各位为:\n";
cout<<i;
cout<<"\n";
cout<<"逆序排列为:\n";
cout<<i<<"\n";}

return 0;

}
2017-01-11 06:48:51
赞 3
相关问答
最新其他问答
解决方法