给出一个不多于5位数的正整数
1:求它是几位数
2:按逆序打印出各位数字,输入:321,输出:123。
我写了个,知道很多语句都重复了,希望大家教个简单点的
#include<iostream>
using namespace std;
int main()
{
int number,a,b,c,d,e,change;
cin>>number;
char ch;
char ch;
ch=(number>=10000)?'a':(number>=1000)?'b':(number>=100)?'c':(number>=10)?'d':e;
switch(ch)
{
case 'a': a=number/10000;
change=number%10000;
b=change/1000;
change=number%1000;
c=change/100;
change=number%100;
d=change/10;
e=number%10;
cout<<"五位数,它的逆序是:"<<e<<d<<c<<b<<a<<endl;
break;
case 'b': b=number/1000;
change=number%1000;
c=change/100;
change=number%100;
d=change/10;
e=number%10;
cout<<"四位数,它的逆序是:"<<e<<d<<c<<b<<endl;
break;
case 'c': c=number/100;
change=number%100;
d=change/10;
e=number%10;
cout<<"三位数,它的逆序是:"<<e<<d<<c<<endl;
break;
case 'd': d=number/10;
e=number%10;
cout<<"两位数,它的逆序是:"<<e<<d<<endl;
break;
default:cout<<"一位数,它的逆序是:"<<number<<endl;
}return 0;
}