#include
#include
using namespace std;
int main() {
int x, y, z;
y = 10;
cout<< "请输入一个正整数:" << endl;
cin >> x;
int n = 1;
for (; n < 10; n++) {
if (x / int((pow(y, n))) == 0) {//用到了幂运算函数pow,返回的值是double型就又int,
break;
}
}
cout << "该整数的位数为:" << n << endl;
if (n == 1) {
cout << (x % 10) << " ";
}
if (n == 2) {
cout << (x % 10) << " ";
cout << (x / 10 ) << " ";
}
int i = 2;
if (n > 2) {
cout << (x % 10) << " " ;
cout << (x / 10 % 10) << " ";
for (; i < n; i++) {
cout << (x / int((pow(y, i))))%10 << " ";
}
}
return 0;
}
原文:https://www.cnblogs.com/-HXF-/p/12497501.html