#include <stdio.h>
#include <math.h>
#define lim 0.00001
void main()
{
int x,y,z;
double a;
printf("There are 3 beers/n");
for(x=2;x<10;x++)
for(y=x+1;y<20;y++)
for(z=y+1;z<30;z++)
{
a=1.0/x+1.0/y+1.0/z;
if (fabs(a-1.0)<lim)
printf("There are %d,%d,%d people drink the beer./n",&x,&y,&z);
}
}
以上是比较完善的程序!
/* Note:Your choice is C IDE */
#include <stdio.h>
void main()
{
int x,y,z;
double a;
printf("There are 3 beers/n");
for(x=2;x<10;x++)
for(y=x+1;y<20;y++)
for(z=y+1;z<30;z++)
{a=1.0/x+1.0/y+1.0/z;
if (a==1.0)
printf("There are %d,%d,%d people drink the beer./n",x,y,z);
}
表面上是对的程序!其实是很错的