Example problem: classical problem: there is a pair of rabbits, from the birth of the 3rd month since every month a pair of rabbits, rabbit children grow to the 3rd month after every month and give birth to a pair of rabbits, if rabbits are not dead, ask the total number of rabbits every month for how many?
The code is as follows:
/* program analysis: the rule of rabbits is 1,1,2,3,5,8,13,21.... * /
#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");/* Control output, four */ per line
f1=f1+f2; /* The first two months add up to the third month */
f2=f1+f2; /* The first two months add up to the third month */}}Copy the code
The output running window is as follows:
Other exercises this week
C programming column
C programming > second week ① Print diamond pattern.
C programming > week 2 ② there is a sequence of fractions: 2/1, 3/2, 5/3, 8/5, 13/8, 21/13… Find the sum of the first 20 terms in this sequence.
③ classical problem: there are a pair of rabbits, from the birth of the third month from every month a pair of rabbits, rabbit children grow to the third month after every month and a pair of rabbits, if the rabbits are not dead, ask the total number of rabbits every month for how many?
C programming > second week ④ determine how many primes there are between 101 and 200, and output all the primes.
C programming > second week ⑤ Input a line of characters and count the number of letters, Spaces, digits and other characters respectively.
Week 2 ⑥ A ball falls from a height of 100 meters freely, each time after the landing bounce back to half of the original height; And when it lands again, how many meters does it travel on the 10th landing? How high is the 10th bounce?
The problem: on the first day, the monkey picked some peaches and ate half of them immediately. It was not enough, so it ate one more peach. The next morning, it ate half of the peaches and one more peach. For the rest of the day, I ate half and one each morning.
Week 8 Two ping-pong teams played a match, with three players each. Team A consists of a, B and C, and team B consists of X, Y and Z. The list of players has been drawn. The players were asked for the match list. A says he doesn’t compare with x, C says he doesn’t compare with x and z, please program it out.
The harder you work, the luckier you get! Come on, Aoli!!