问题描述:
给一个不多于五位数的正整数。
要求:
1.求出他是几位数
2.分别输出每一位数字
3.按逆序输出每一位数字
#include <iostream>
using namespace std;
int main()
{
int i,a[5],n=0,j;
cin>>i;
while(i)
{
a[n++]=i%10;
i=i/10;
}
cout<<n<<endl;
for(j=n-1;j>=0;--j)
cout<<a[j]<<' ';
cout<<endl;
for(j=0;j<n;j++)
cout<<a[j]<<' ';
cout<<endl;
return 0;
}
运行结果:
学习总结;
这个题是曹爱妃告诉我的,一开始做想的很复杂,关于几位数的判断迟迟不知道怎么写,后来问了一下度娘,有种豁然开朗的感觉。