首页 > 编程语言 > 详细

C++ 穷举算法 鸡兔同笼

时间:2019-07-07 13:22:50      阅读:332      评论:0      收藏:0      [点我收藏+]
 1 #include "stdio.h"
 2 int qiongju(int head, int foot, int *chicken, int *rabbit)
 3 {
 4     int re, i, j;
 5     re = 0;
 6     for (i = 0; i <= head; i++)
 7     {
 8         j = head - i;
 9         if (i * 2 + j * 4 == foot)
10         {
11             re = 1;
12             *chicken = i;
13             *rabbit = j;
14         }
15     }
16     return re;
17 }
18 
19 void main()
20 {
21     int chicken, rabbit, head, foot;
22     int re;
23 
24     re = qiongju(head,foot,&chicken,&rabbit);
25 
26     if (re == 1)
27     {
28         printf("鸡有:%d 只,兔子有:%d 只。\n",chicken,rabbit);
29     }
30     else 
31     {
32         printf("无法求解!\n");
33     }
34 }

注意变量 re !!!

C++ 穷举算法 鸡兔同笼

原文:https://www.cnblogs.com/zhibei/p/11145694.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!