File tree Expand file tree Collapse file tree
JavaScript Interview Programs Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44// 1. Generate fibonacci of a Number:
55
66// Generate Fibonacci of a number using for loop():
7- function fibonacciF ( n ) {
7+ function fibonacciF ( n )
8+ {
89 let num1 = 0 , num2 = 1 , next ;
910 console . log ( "Fibonacci using for loop:" ) ;
10- for ( let i = 1 ; i <= n ; i ++ ) {
11+ for ( let i = 1 ; i <= n ; i ++ )
12+ {
1113 console . log ( num1 ) ;
1214 next = num1 + num2 ;
1315 num1 = num2 ;
@@ -28,10 +30,12 @@ fibonacciF(7);
2830// OR
2931
3032// Generate Fibonacci of a Number Using While Loop:
31- function fibonacciW ( n ) {
33+ function fibonacciW ( n )
34+ {
3235 let num1 = 0 , num2 = 1 , count = 0 ;
3336 console . log ( "Fibonacci Using While Loop:" ) ;
34- while ( count < n ) {
37+ while ( count < n )
38+ {
3539 console . log ( num1 ) ;
3640 let temp = num1 + num2 ;
3741 num1 = num2 ;
@@ -51,7 +55,8 @@ fibonacciW(7);
5155// 8
5256
5357// 2. Generate Fibonacci of a Number Using Recursion
54- function fibonacciR ( n ) {
58+ function fibonacciR ( n )
59+ {
5560 if ( n <= 1 ) return n ;
5661 return fibonacciR ( n - 1 ) + fibonacciR ( n - 2 ) ;
5762}
You can’t perform that action at this time.
0 commit comments