编程三位数怎么输出

时间:2025-01-28 16:20:14 网络游戏

C++

```cpp

include

using namespace std;

int main() {

int n;

cin >> n;

int a = n / 100;

int b = (n - a * 100) / 10;

int c = n % 10;

cout << "百: "<< a << ", 十: "<< b << ", 个: "<< c << endl;

return 0;

}

```

Java

```java

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.print("请输入一个三位整数: ");

int i = input.nextInt();

System.out.println("百位上的数是: " + (i / 100));

System.out.println("十位上的数是: " + ((i / 10) % 10));

System.out.println("个位上的数是: " + (i % 10));

}

}

```

Python

```python

num = int(input("请输入一个三位整数: "))

print(f"百: {num // 100}, 十: {num // 10}, 个: {num % 10}")

```

C语言

```c

include

int main() {

int n, a, b, c;

scanf("%d", &n);

a = n / 100;

b = (n - a * 100) / 10;

c = n % 10;

printf("%d%d%d\n", c, b, a);

return 0;

}

```

JavaScript

```javascript

let num = parseInt(prompt("请输入一个三位整数:"));

console.log(`百: ${Math.floor(num / 100)}, 十: ${Math.floor((num % 100) / 10)}, 个: ${num % 10}`);

```

这些示例展示了如何在不同的编程语言中读取一个三位数,并将其分解为百位、十位和个位,然后分别输出这些数字。你可以选择适合你的编程语言进行尝试。