C Language Programming Introduction Topic-No.11

Topic: Classical question: There are a pair of rabbits. From the third month after birth, a pair of rabbits will be born every month. When the little rabbit grows to the third
month, a pair of rabbits will be born every month. What is the total number of rabbits per month?
1. Program analysis: The law of rabbits is the sequence of numbers 1,1,2,3,5,8,13,21 ...
2. Program source code:

#include "stdio.h"
main()
{
    long f1, f2;
    int i;
    f1 = f2 = 1;
    for (i = 1; i <= 20; i++)
    {
        printf("%12ld %12ld", f1, f2);
        if (i % 2 == 0)
            printf("\n"); /*控制输出,每行四个*/
        f1 = f1 + f2;     /*前两个月加起来赋值给第三个月*/
        f2 = f1 + f2;     /*前两个月加起来赋值给第三个月*/
    }
}
Published 678 original articles · praised 343 · 70,000 views

Guess you like

Origin blog.csdn.net/weixin_43627118/article/details/105462564