The hen has 5 yuan, the rooster has 3 yuan, and the chicken has 3 yuan. Buy 100 chickens for 100 yuan now and find all possible solutions.
Algorithm analysis:
Set hen, Rooster, and chicken to X, Y, and Z respectively,
1. Two conditions must be met: X + Y + z = 100 and
5x + 3y + z/3 = 100
2. For such actual problems, consider the value range of X, Y, and Z:
0 <= x <= 100,
0 <= y <= 100,
0 <= z <= 100
# Include <iostream>
Using namespace STD;
Int main ()
{Int x, y, z;
For (x = 0; X <= 100; X ++)
For (y = 0; y <= 100; y ++)
For (Z = 0; Z <= 100; Z ++)
If (x + y + z = 100 & 5 * x + 3 * Y + z/3 = 100)
Cout <x <''<Y <'' <z <Endl;
System ("pause"); return 1;
}
**************************************** *****************************
# Include <iostream>
Using namespace STD;
Int main ()
{Int x, y, z;
For (x = 0; x <= 14; X ++)
{Y = 100-7 * X;
If (Y % 4) continue; else y/= 4;
Z= 100-x-y;
If (Z % 3) continue;
Cout <x <''<Y <'' <z <Endl;
}
System ("pause"); return 1;
}
Hundreds of chickens and hundreds of dollars