100C之16:卖金鱼

Table of Contents

问题

买买提将养的一缸金鱼分五次出售:第一次卖出全部的一半加上二分之一条;第二次卖出余下的三分之一加三分之一条;第三次卖出余下的四分之一加四分之一条;第四次卖出余下的五分之一加五分之一条;最后卖出余下的11条。问原来鱼缸中有多少条鱼?

分析

此题和100C之15有异曲同工之妙。

解决方案

 1:  /**
 2:   * @file   016sellgoldfish.c
 3:   * @author Chaolong Zhang <emacsun@163.com>
 4:   * @date   Thu May 16 19:35:39 2013
 5:   */
 6:  
 7:  #include <stdio.h>
 8:  
 9:  int main(int argc, char *argv[])
10:  {
11:      int a;
12:      float b,c,d,e;
13:      for (a=11; a < 1000; ++a)
14:      {
15:          b= a - ( a/2 +1/2 );
16:          c= b - ( b/3 +1/3 );
17:          d= c - ( c/4 +1/4 );
18:          e= d - ( d/5 +1/5 );
19:          if ((int)e == 11 )
20:          {
21:              printf ("yes the number is %d %f\n", a,e);
22:          }
23:      }
24:      return 0;
25:  }
posted @ 2013-05-16 20:47  emacsun  阅读(608)  评论(0编辑  收藏  举报