<一道题>abc+cba=1333,求满足条件的abc的值,隐含条件a!=0,c!=0

时间:2024-11-09 10:06:08

这类东西,无非就是穷举法。见下面代码:

#include <stdio.h>
#include <stdlib.h> /*
*abc + cba = 1333
*
*a = ?
*b = ?
*c = ?
*/ int main(int argc ,char **argv)
{
int a=;
int b=;
int c=; int index = ; printf("abc + cba == 1333\n"); for(a = ; a <= ; a++)//a [1,9]
{
for(b = ; b <= ; b++)//b [0,9]
{
for(c = ; c <= ; c++)//c [1,9]
{
if( == (*a + *b + c + *c + *b + a))
{
index++;
printf("I have found it !!! index : %d , a= %d, b= %d, c=%d\n",index,a,b,c);//多谢1楼仁兄,找到了,却没有注意英文语法,已改found及I }
}
}
} printf("find over\n");
return ;
}

运行结果;

tiger@ubuntu:/mnt/hgfs/e/Lessons/MyExercise/UtilLibs/EXERCISE$ ./abc
abc + cba == 1333
I have found it !!! index : 1 , a= 4, b= 1, c=9
I have found it !!! index : 2 , a= 5, b= 1, c=8
I have found it !!! index : 3 , a= 6, b= 1, c=7
I have found it !!! index : 4 , a= 7, b= 1, c=6
I have found it !!! index : 5 , a= 8, b= 1, c=5
I have found it !!! index : 6 , a= 9, b= 1, c=4
find over
tiger@ubuntu:/mnt/hgfs/e/Lessons/MyExercise/UtilLibs/EXERCISE$