abc问题
-
题目描述
设abc是0-9之间的数字,abc,bcc是两个三位数,且有abc+bcc=532,求所有满足条件的abc的值 -
输入
题目没有任何输入 -
输出
请输出所有满足题目条件的a,b,c的值,a,b,c之间用空格隔开,每个输出占一行
题解
#include<cstdio>
int main() {
int a, b, c;//定义了三个名字为a,b,c的三个整型变量
for (a = 0; a <= 9; a++) {
for (b = 0; b <= 9; b++) {
for (c = 0; c <= 9; c++) {
int s = a * 100 + b * 110 + c * 12;
if (s == 532) {
printf("%d %d %d\n", a, b, c);
}
}
}
}
}
输出
3 2 1
反序数
-
题目
设N是一个4位数,它的9倍恰好是其反序数(如1234的反序数4321),求N的值 -
输入
题目没有要求 -
输出
输出题目要求的4位数,如果结果有多组,那么每组结果之间可以回车隔开
题解
#include<cstdio>
int Reverse(int n) {
int remain;
int reverse = 0;
while (n > 0) {
remain = n% 10;
n /= 10;
reverse = reverse * 10 + remain;
}
return reverse;
}
int main() {
int a, b, c, d;
for (a = 1; a <= 9; a++) {
for (b = 0; b <= 9; b++) {
for (c = 0; c <= 9; c++) {
for (d = 0; d <= 9; d++) {
int n = 1000 * a + 100 * b + 10 * c + d;
if (n * 9 == Reverse(n)) {
printf("%d\n", n);
}
}
}
}
}
}
输出
1089
对称平方数
-
题目
打印所有不超过256,其平方具有对称性质的数,如2和11就是这样的数,因为2x2=4,11x11=121 -
输入
题目没有任何输入 -
输出
输出具有题目要求的性质的数,如果输出的数据不止一组,那么各组之间以回车隔开
题解
#include<cstdio>
int Reverse(int n) {
int reverse = 0;
int remain;//每次的余数
while (true) {
remain = n % 10;
reverse = reverse * 10 + remain;
n /= 10;
if (n == 0) {
break;
}
}
return reverse;
}
int main() {
int i = 0;
for (i = 0; i <= 256; i++) {
if (i * i == Reverse(i*i)) {
printf("%d\n", i);
}
}
}
输出
0
1
2
3
11
22
26
101
111
121
202
212