#include using namespace std;

int main() { int n; cin >> n; int count = 0; // 记录位数 int temp = n; while (temp > 0) { count++; temp /= 10; } cout << '位数:' << count << endl; cout << '每位数字:'; for (int i = count; i > 0; i--) { int digit = n / pow(10, i-1); cout << digit << ' '; n %= (int)pow(10, i-1); } cout << endl; cout << '逆序数字:'; while (n > 0) { int digit = n % 10; cout << digit << ' '; n /= 10; } cout << endl; return 0; }

C++ 程序:获取正整数的位数、数字和逆序数字

原文地址: https://www.cveoy.top/t/topic/l5mO 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录