/* Requirements: Define a function, accept a positive integer, and return the Fibonacci number corresponding to that parameter
Introduction: Fibonacci Number The first 2 numbers are 1, starting from the third is the sum of the first 2 numbers, as follows:
1, 1, 2, 3, 5, 8, 13, 21, 34......*/
<! DOCTYPE html>/*requirements: Define a function, accept a positive integer and return the Fibonacci number corresponding to the parameter: Fibonacci number The first 2 numbers are 1, starting from the third is the sum of the first 2 numbers, as follows: 1, 1, 2, 3, 5, 8, 13, 21 , ...*/ functionFibonacci (n) {if(n==0) {return0;} if(n==1) {return1;} returnFibonacci (n-1) + Fibonacci (n-2); } for(vari=1;i<10;i++){ varRET =Fibonacci (i); Console.log (ret); } </script>/* Requirements: Define a function that accepts a positive integer argument that means a number of rows, such as a Yang Hui triangle that defaults to 5 if not supplied, and outputs the corresponding number of rows
Description: Each number is the sum of its two shoulders, if missing a shoulder, then replaced by 0, for example: 5th row 3rd number, is the 4th row 2nd, 3 numbers of the sum;
The first number on line 4th is the sum of the first number of lines 0 and 3rd.
1
1 1
1 2 1
1 3 3 1
1 4 6) 4 1
<! DOCTYPE html>/*requirements: Define a function, accept the meaning of a positive integer parameter of the number of rows, if not provided by default is 5, output the corresponding number of Yang Hui triangle description: Each number is the sum of its two shoulders, if missing a shoulder, then 0 instead, for example: 5th row 3rd number, is the 4th row 2nd, 3 number of the sum; The first number on line 4th is the sum of the first number of lines 0 and 3rd*/ //1 //1 1 //1 2 1 //1 3 3 1 //1 4 6) 4 1 functionYanghui (row,col) {if(Row<1 | | col<1){ return0; } if(row==1 | | col==row | | col==1){ return1; } returnYanghui (ROW-1,COL-1) +yanghui (row-1, COL)} Console.log (Yanghui (3,2)); </script>April 5--an exercise on algorithms--Fibonacci numbers--Yang Hui triangles