Question:
There was a rabbit who had a rabbit every month since 3rd months after birth. After the third month, the rabbit had a rabbit every month. If the rabbit was not dead, what is the total number of rabbits per month?
ProgramAnalysis: the rabbit rule is a sequence of numbers 1, 1, 2, 3, 5, 8, 13, 21 ....
Bytes ---------------------------------------------------------------------------------------------------------
Here is myCodeYou are welcome to post the results.
C #
Class Program { Static Void Main ( String [] ARGs) {thefirst ( 10 ); Console. Readline ();} // [Procedure 1] // Question: classical question: there is a rabbit who has given birth to a rabbit every month since 3rd months after birth. After the third month, the rabbit has given birth to another rabbit every month. // For rabbits, if they do not die, how many rabbits are there each month? // 1. program analysis: the rabbit rule is a sequence of numbers 1, 1, 2, 3, 5, 8, 13, 21 .... Private Static Void Thefirst ( Int Month ){ Int Num =1 ; For ( Int I = 1 ; I <= month; I ++ ){ If (I> 2 ) {Num ++ ; Createtu (I - 2 , Ref Num);} console. writeline ( " Month {0}: {1} " , I, num );}} Private Static Void Createtu ( Int Month, Ref Int Num ){ For ( Int I = 1 ; I <= month; I ++){ If (I> 2 ) {Num ++ ; Createtu (I - 2 , Ref Num );}}}
JS version
<Script language = "JavaScript" type = "text/JavaScript"> VaR Num = 1 ; Function Thefirst (month ){ For ( VaR I = 1; I <= month; I ++ ){ If (I> 2 ) {Num ++ ; Createtu (I -2 );} Document. Body. innerhtml + = "+" + I + "month:" + num + "+" </BR>" ;}} Function Createtu (month ){ For (VaR I = 1; I <= month; I ++ ){ If (I> 2 ) {Num ++ ; Createtu (I -2 );}}} </SCRIPT>
For more questions, see 50 arithmetic questions.