April 5--an exercise on algorithms--Fibonacci numbers--Yang Hui triangles

Source: Internet
Author: User

/* 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.