C 练习实例11

C 语言教程 · 2019-02-21 14:44:33

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

程序分析:兔子的规律为数列1,1,2,3,5,8,13,21....,即下个月是上两个月之和(从第三个月开始)。

程序源代码:

// Created by www.codercto.com on 15/11/9. // Copyright © 2015年 码农教程. All rights reserved. // #include<stdio.h> int main() { int f1=1,f2=1,i; for(i=1;i<=20;i++) { printf("%12d%12d",f1,f2); if(i%2==0) printf("\n"); f1=f1+f2; f2=f1+f2; } return 0; }

以上实例输出结果为:

           1           1           2           3
           5           8          13          21
          34          55          89         144
         233         377         610         987
        1597        2584        4181        6765
       10946       17711       28657       46368
       75025      121393      196418      317811
      514229      832040     1346269     2178309
     3524578     5702887     9227465    14930352
    24157817    39088169    63245986   102334155

点击查看所有 C 语言教程 文章: https://codercto.com/courses/l/17.html

查看所有标签

HTML Dog

HTML Dog

Patrick Griffiths / New Riders Press / 2006-11-22 / USD 49.99

For readers who want to design Web pages that load quickly, are easy to update, accessible to all, work on all browsers and can be quickly adapted to different media, this comprehensive guide represen......一起来看看 《HTML Dog》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具