zoukankan      html  css  js  c++  java
  • 【程序1】

    题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?

    
    //这是一个菲波拉契数列问题
    
    public class lianxi01 {
    
        public static void main(String[] args) {
    
            System.out.println("第1个月的兔子对数:    1");
    
            System.out.println("第2个月的兔子对数:    1");
    
            int f1 = 1, f2 = 1, f, M=24;
    
            for(int i=3; i<=M; i++) {
    
              f = f2;
    
              f2 = f1 + f2;
    
              f1 = f;
    
              System.out.println("第" + i +"个月的兔子对数: "+f2);
    
            }
    
        }
    
    }
  • 相关阅读:
    hdoj:2033
    hdoj:2032
    hdoj:2031
    hdoj:2029
    hdoj:2028
    hdoj:2027
    hdoj:2024
    hdoj:2023
    hdoj:2022
    hdoj:题目分类
  • 原文地址:https://www.cnblogs.com/yuyu666/p/9839745.html
Copyright © 2011-2022 走看看