char str[10];
scanf("%s",str);
printf("%d位數",strlen(str));
printf(str);
int i=strlen(str)-1;
while(i>=0)printf("%c",str[i--]);
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;
}