数学题

来源:互联网 发布:淘宝企业店铺怎么退出 编辑:程序博客网 时间:2024/04/28 10:06

马克思手稿中有一道趣味
数学
问题:有30个人,其中有男人、女人和小孩,在一家饭馆吃饭共花了50先令;每个男人花3先令,每个女人花2先令,每个小孩花1先令;问男人、女人和小孩各有几人?编程,输出全部可能的答案。

 1 #include <stdio.h>

  2 
  3 int main()
  4 {
  5     int x, y, z,count=0;
  6     printf("MEN    WOMEN    CHILDREN\n");
  7     for (x=0; x<=10; x++)
  8     {
  9         y= 20 - 2*x;
 10         z= 30 - x - y;
 11         if (50==3*x + 2*y + z)
 12         {
 13             printf(" %2d:    %d    %d    %d\n", ++count, x, y, z);
 14         }
 15     }
 16     return 0;

 17 }

[root@localhost 41]# vim men.c 
[root@localhost 41]# gcc men.c 
[root@localhost 41]# ,.a
bash: ,.a: command not found
[root@localhost 41]# ./a.out 
MEN    WOMEN    CHILDREN
  1:    0    20    10
  2:    1    18    11
  3:    2    16    12
  4:    3    14    13
  5:    4    12    14
  6:    5    10    15
  7:    6    8    16
  8:    7    6    17
  9:    8    4    18
 10:    9    2    19
 11:    10    0    20

0 0
原创粉丝点击