085.百钱百鸡问题
【摘要】
#include<stdio.h>void main(){ int x,y,z,j=0; clrscr(); puts("************************************************"); puts("* This program is to solve ...
-
#include<stdio.h>
-
void main()
-
{
-
int x,y,z,j=0;
-
clrscr();
-
puts("************************************************");
-
puts("* This program is to solve Problem of *");
-
puts("* Hundred Yuan Hundred Fowls. *");
-
puts("* Which is presented by Zhang Qiujiang, *");
-
puts("* a Chinese ancient mathematician, in his work *");
-
puts("* Bible of Calculation: 5 Yuan can buy 1 cock, *");
-
puts("* 3 Yuan can buy 1 hen, 1 Yuan buy 3 chickens, *");
-
puts("* now one has 100 Yuan to buy 100 fowls, the *");
-
puts("* question is how many cocks, hens, chickens *");
-
puts("* to buy? *");
-
puts("************************************************");
-
printf("\n The possible plans to buy 100 fowls with 100 Yuan are:\n\n");
-
for(x=0;x<=20;x++) /*外层循环控制鸡翁数*/
-
for(y=0;y<=33;y++) /*内层循环控制鸡母数y在0~33变化*/
-
{
-
z=100-x-y; /*内外层循环控制下,鸡雏数z的值受x,y的值的制约*/
-
if(z%3==0&&5*x+3*y+z/3==100)
-
/*验证取z值的合理性及得到一组解的合理性*/
-
printf("%2d: cock=%2d hen=%2d chicken=%2d\n",++j,x,y,z);
-
}
-
puts("\n Press any key to quit...");
-
getch();
-
}
文章来源: blog.csdn.net,作者:程序员编程指南,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/weixin_41055260/article/details/124518702
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)