1.百钱百鸡
#include <stdio.h>
int main()
{
int cock, hen, chicken;
for (cock = 0; cock <= 20; cock++)
{
for (hen = 0; hen <= 33; hen++)
{
for (chicken = 0; chicken <= 100; chicken++)
{
if ((5 * cock + 3 * hen + chicken/3.0 == 100)&&(cock + hen + chicken == 100))
printf("公鸡%d只,母鸡%d只,小鸡%d只\n", cock, hen, chicken);
}
}
}
}
2.选书方案
#include <stdio.h>
int main()
{
int a, b, c, i = 0;//a,b,c分别表示A,B,C借阅的图书编号,i表示有效借阅次数
for (a = 1; a <= 5; a++)
{
for (b = 1; b <= 5; b++)
{
for (c = 1; c <= 5; c++)
{
if (a != b && b != c &&a != c)
{
i++;
printf("A:%d, B:%d, C:%d\n", a, b, c);
}
}
}
}
printf("共有%d种方案\n", i);
return 0;
}