PAT基础编程题目-7-3 逆序的三位数
程序员文章站
2022-06-07 11:39:27
...
PAT基础编程题目-7-3 逆序的三位数
题目详情
解答
C语言版
#include<stdio.h>
int main() {
int array[3];
int number;
scanf("%d", &number);
for (int i = 0; i < 3; i++)
{
array[i] = number % 10;
number = number / 10;
}
for (int j = 0; j < 3; j++)
{
if (array[j] || (array[1]==0 && array[0]!=0) )
printf("%d", array[j]);
}
return 0;
}
C++版
#include<iostream>
using namespace std;
int main() {
int array[3];
int number;
cin >> number;
for (int i = 0; i < 3; i++)
{
array[i] = number % 10;
number = number / 10;
}
for (int j = 0; j < 3; j++)
{
if (array[j] || (array[1] == 0 && array[0] != 0))
cout << array[j];
}
return 0;
}
Java版
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
int number = 0;
int [] array = new int[3];
Scanner scanner = new Scanner(System.in);
if(scanner.hasNext()) {
number = scanner.nextInt();
}
scanner.close();
for (int i = 0; i < array.length; i++) {
array[i] = number%10;
number = number/10;
}
for (int j = 0; j < array.length; j++) {
if (array[j]!=0 || (array[1]==0 && array[0]!=0)) {
System.out.print(array[j]);
}
}
}
}
创作不易,喜欢的话加个关注点个赞,谢谢谢谢谢谢!
上一篇: Mysqladmin -help 命令_MySQL
下一篇: PHP文件上传主要代码讲解_PHP教程