酷代码 AI
菜单
服务商

用 C++、C、Java、Python、Pascal 五种语言实现从整数个位开始分离每一位数字

C++ 实现 ```cpp #include <iostream> using namespace std; int main() { long long x; cin >> x; // 处理负数情况 if (x < 0) x = -x; do { cout << x % 10; x /= 10; if (x > 0) cout << " "; } while (x > 0); return 0; } ``` C 实现 ```c #include <stdio.h> int main() { long long x; scanf("%lld", &x); // 处理负数情况 if (x < 0) x = -x; do { printf("%lld", x % 10); x /= 10; if (x > 0) printf(" "); } while (x > 0); 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(); // 处理负数情况 x = Math.abs(x); boolean first = true; do { if (!first) { System.out.print(" "); } System.out.print(x % 10); x /= 10; first = false; } while (x > 0); scanner.close(); } } ``` Python 实现 ```python x = int(input()) # 处理负数情况 x = abs(x) digits = [] while x: digits.append(x % 10) x //= 10 if not digits: digits = [0] print(" ".join(map(str, digits))) ``` Pascal 实现 ```pascal program SeparateDigits; var x: int64; first: boolean; begin readln(x); // 处理负数情况 if x < 0 then x := -x; first := true; repeat if not first then write(' '); write(x mod 10); x := x div 10; first := false; until x = 0; end. ``` ######[AI问答 | 561点数解答 | 2025-12-07 12:45:11]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]