酷代码 AI
菜单
服务商

给了你一个整数 𝑥 ,要求从个位开始分离出它的每一位数字。 输入 输入一个整数 𝑥 [ 𝑙 𝑜 𝑛 𝑔 𝑙 𝑜 𝑛 𝑔 ] 。 输出 从个位开始按照从低位到高位的顺序依次输出每一位数字。数字之间以一个空格分开 样例输入 复制 123 样例输出 复制 3 2 1

Python ```python x = int(input()) digits = [] while x > 0: digits.append(x % 10) x //= 10 print(' '.join(map(str, digits))) ``` Pascal ```pascal program SeparateDigits; var x: int64; begin readln(x); if x = 0 then write(0) else begin while x > 0 do begin write(x mod 10, ' '); x := x div 10; end; end; end. ``` C++ ```cpp #include <iostream> using namespace std; int main() { long long x; cin >> x; if (x == 0) { cout << 0; } else { while (x > 0) { cout << x % 10 << ' '; x /= 10; } } return 0; } ``` C ```c #include <stdio.h> int main() { long long x; scanf("%lld", &x); if (x == 0) { printf("0"); } else { while (x > 0) { printf("%lld ", x % 10); x /= 10; } } return 0; } ``` Java ```java import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); long x = scanner.nextLong(); if (x == 0) { System.out.print(0); } else { while (x > 0) { System.out.print(x % 10 + " "); x /= 10; } } } } ``` [2025-12-27 19:48:49 | AI问答 | 386点数解答]

相关提问
发财导航,免费问AI
实用工具查看更多