提供下我的代码
#define MAX_DEPTH 4
int goodnum = 0;
//满足条件的数量
int allnum = 0;
void calc(int depth,float a, float b);
int main(int argc, char **argv)
{
calc(0, 1000, 2000);
printf("%d / %d = %f\n", goodnum , allnum, (float)goodnum / allnum);
return 0;
}
void calc(int depth ,float a, float b)
{
if (MAX_DEPTH == depth++)
{
allnum++;
if (fabs(a - b ) >=1000)
{
goodnum++;
}
return;
}
calc(depth, a * ((float)1 * 3 / 4), b * ((float)1 * 5 / 4));
calc(depth, a * ((float)1 * 5 / 4), b * ((float)1 * 3 / 4));
}