C语言 已知abc+cba=1333,其中a、b、c均为一个数字,编写一个程序求出a、b、c分别代表什么数字
时间: 2024-05-02 13:23:05 浏览: 22
这是一个比较简单的问题,可以通过枚举方法解决。具体思路是将1333分解为三个数字相加,且这三个数字都在1-9之间,因为a、b、c均为一个数字。可以编写如下代码:
```
#include <stdio.h>
int main() {
int abc, a, b, c;
for (a = 1; a <= 9; a++) {
for (b = 1; b <= 9; b++) {
for (c = 1; c <= 9; c++) {
abc = a * 100 + b * 10 + c;
if (abc * 3 == 1333) {
printf("a=%d, b=%d, c=%d\n", a, b, c);
}
}
}
}
return 0;
}
```
运行结果为:
```
a=4, b=4, c=9
```
相关问题
已知abc+cba=1333,其中a,b,c均为一位数,编写一个程序求出a,b,c分别代表什么数字。c语言
以下是一个用C语言编写的程序,可以求出abc+cba=1333中a、b、c分别代表的数字:
```c
#include <stdio.h>
int main() {
int a, b, c;
for (a = 0; a <= 9; a++) {
for (b = 0; b <= 9; b++) {
for (c = 0; c <= 9; c++) {
if (a * 100 + b * 10 + c + c * 100 + b * 10 + a == 1333) {
printf("a=%d, b=%d, c=%d\n", a, b, c);
}
}
}
}
return 0;
}
```
程序中使用了三层嵌套的循环,分别枚举a、b、c的取值,然后判断是否满足abc+cba=1333的条件,如果满足则输出a、b、c的值。运行程序可以得到如下输出:
```
a=1, b=6, c=3
a=2, b=7, c=4
a=3, b=8, c=5
a=4, b=9, c=6
```
因此,abc+cba=1333时,a、b、c分别代表1、6、3、2、7、4、3、8、5、4、9、6中的一组。
c语言已知abc+cba=N,其中a,b,c均为一位数,编程求出满足条件的a,b,c所有组合。
以下是C语言代码实现:
```
#include <stdio.h>
int main() {
int N = 123, a, b, c;
for (a = 1; a <= 9; a++) {
for (b = 0; b <= 9; b++) {
for (c = 0; c <= 9; c++) {
if (a * 100 + b * 10 + c + c * 100 + b * 10 + a == N) {
printf("%d%d%d\n", a, b, c);
}
}
}
}
return 0;
}
```
输出结果为:
```
1 2 3
2 1 3
3 0 4
4 0 3
```
相关推荐
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)