//给一个不多于5位的正整数,
//要求:一、求它是几位数,二、逆序打印出各位数字。
#include <iostream>
using namespace std;
int main()
{
int a,b,c,d,e,x;
cout<<"Please input the number ";
cin>>x;
a=x/10000;
b=(x/1000)%10;
c=(x/100)%10;
d=(x/10)%10;
e=x%10;
if(a!=0){
cout<<"The length of the number is 5"<<endl;
cout<< e << d << c << b << a << endl ;
}else if(b!=0){
cout<<"The length of the number is 4"<<endl;
cout<< e << d << c << b << endl ;
}else if(c!=0){
cout<<"The length of the number is 3"<<endl;
cout<< e << d << c << endl ;
}else if(d!=0){
cout<<"The length of the number is 2"<<endl;
cout<< e << d << endl ;
}else{
cout<<"The length of the number is 1"<<endl;
cout<< e << endl ;
}
return 0;
}
运行结果为
- class='magplus' title='点击查看原始大小图片' />
- 大小: 35.6 KB