0 thích 0 k thích
1.2k đã xem

Please use recursive function. 請使用遞迴函數

In mathematics, the Fibonacci numbers or Fibonacci sequence are the numbers in the following integer sequence: 0,1,1,2,3,5,8,13,21,34,55,89,144

前13的斐波那契數列:0,1,1,2,3,5,8,13,21,34,55,89,144

By definition, the first two numbers in the Fibonacci sequence is 0 and 1, and each subsequent number is the sum of the previous two. In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the relation  with seed values F0 = 0, F1= 1

斐波那契數由0和1開始,其後的數就由之前的兩個數相加。用數學表示 F0 = 0, F1 = 1

Write a program that asks the user to type an integer n, then display Fn on the screen.

寫一個輸入一個整數n,輸出第n個斐波那契數的程式

Example input 1:

5

Example output 1:

5

 

Example input 2:

12

Example output 2:

144

 

[Exercise] Coding (C) - đã hỏi trong Chapter 9: Functions bởi (5.2k điểm)
ID: 37370 - Xem được từ: 2017-12-14 18:00 - Hiệu lực đến: Không giới hạn
| 1.2k đã xem

41 Trả lời

0 thích 0 k thích
Hidden content!
#include **** * ** * *
int F(int n)
{
*** * * * ** * ** * *****
* * * * * * * * * **** 1;
** ** * ** * * *
** ****** *** * ** 0;
******* * ** * ** **** F(n-1)+F(n-2);
}

int main(void)
{
**** ** ** * *** n;
* * * *** * *** ** *** *** ** *** **
*** ** ****** ** * ** * ** *** **

** * ** * **** ** ** 0;
}
trả lời bởi (-140 điểm)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 thích 0 k thích
Hidden content!
#include * ******
int F(int n)
{
* **** ****** ** *
* ** **** * ** ** *** 1;
** *** ** ********* **
* * **** ******* 0;
* * *** * * ****** F(n-1)+F(n-2);
}

int main(void)
{
* * *** ** * n;
* * **** ** * * ** *** *** *
* * ** ** ** *** * * ** * * * * ** * ** **

* * * ** *** ** **** 0;
}
trả lời bởi (-32 điểm)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 thích 0 k thích
Hidden content!
int F(int n)
{
*** **** * * ****
*** * ** *** * * ** *** 1;
*** * ** * ** * * *
*** ** ** * * 0;
* ******* ** * F(n-1)+F(n-2);
}

int main(void)
{
* * ** * n;
* * * * * * ******* ** *** *** * *
****** ****** * * **** **** * * *** ** *** ***

*** * ** * * ** 0;
}
trả lời bởi (-32 điểm)
0 0
prog.c: In function 'main':
prog.c:13:4: warning: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
    scanf("%d",&n);
    ^~~~~
prog.c:13:4: warning: incompatible implicit declaration of built-in function 'scanf'
prog.c:13:4: note: include '<stdio.h>' or provide a declaration of 'scanf'
prog.c:14:4: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
    printf("%d",F(n));
    ^~~~~~
prog.c:14:4: warning: incompatible implicit declaration of built-in function 'printf'
prog.c:14:4: note: include '<stdio.h>' or provide a declaration of 'printf'
0 thích 0 k thích
Hidden content!
#include <stdio.h>
int fibo(int);

int main()
{
* * ** * ****** *** num;
*** ** *** * * *** *** * ** result;

* * * * * * *** ** ** *** * &num);
** * ** ** *** *** * *** (num > 0)
* ** * * ** * *** **
* ** ** * ** * * * **** *** ** * *** * * * * * ****** = fibo(num);
* * * * * * * * **** * * * ** * ** * ** * * ***** * * *** **
** * **** * * * * *
* * * * *** *** ** * * * * 0;
}
int fibo(int num)
{
*** ** ** * * *** (num == 0)
* *** *** ** **
* * * ******** * ** *** *** * * * ** * * * ** 0;
** * * ** *** * *
* *** ***** ****** *** if (num == 1)
******* ** ** ** *** *** ***
* ** ** *** * * ** ** ** ** * * * * * * ******* 1;
** * ** ** ** ***** ******
******* * * * * * ** ** ***
* *** * * *** * ** *
** ** ** ** **** ** * ** ** *** * * * *** ** **** * * ** - 1) + fibo(num - 2));
    }
}
trả lời bởi (-284 điểm)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 thích 0 k thích
Hidden content!
#include <stdio.h>
int fibo(int);

int main()
{
* *** ***** ** * * * num;
* * * * ** ** *** result;

* ****** * * ** ** * *** * **** * &num);
** **** *** ** * * (num > 0)
*** ** ** * ****** *
* * ** ** * * *** ** ***** *** * *** * * * = fibo(num);
* * * **** ** ** ***** * ** ***** **** ** * * * *
*** * ** * * * ****
***** * * ** ** **** ** 0;
}
int fibo(int num)
{
* ** * * ** * * * (num == 0)
****** * * ** * **** * ** **
** * *** ** * *** * * * **** * ** * * ***** * * * 0;
** * ******* ** * ****
** ** *** *** ** * *** if (num == 1)
* ** * * * ***
*** *** * * * * * ** ** * ****** * * ** * 1;
* *** * * **** * **
* * * ** *** * * *
** * * *** ***** * * *
* **** * * *** * * * * **** * *** ** *** * ** ** **** * - 1) + fibo(num - 2));
    }
}
trả lời bởi (-108 điểm)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 thích 0 k thích
Hidden content!
#include <stdio.h>
int fibo(int);

int main()
{
* * ** * * ** ** num;
* * ** *** ** * * * * result;

** * ***** * *** * ** *** ** * *** &num);
* * *** *** * ** * ** ** (num > 0)
* * *** * *** ** **
***** * ** ***** *** ****** ** * * * * ********** * * = fibo(num);
* *** * * **** * * *** *** * * ** ** *** ** * * * ** * ***
* ** * ** ***** **
* * * **** * * ** ** *** * **** 0;
}
int fibo(int num)
{
* * * ** * * *** * (num == 0)
* * ****** * * *** *
** **** * * * *** * ** **** * ******** ** ** * * ** 0;
* ***** ** * ** *
*** * *** ****** * if (num == 1)
** * * **** ** *** **
* ** * **** * ** ********* * * **** *** * 1;
* ** **** ** **** *
* * * *** * * * ** * * * *
* *** * * **** ** **** ** *
* **** ** * * * * ** * * **** ** *** - 1) + fibo(num - 2));
    }
}
trả lời bởi (-168 điểm)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 thích 0 k thích
Hidden content!
#include ***** * * *

int fn_num(int number)
{
***** * * * * * * * * == 0)
* **** ******* ** * * ******** ** *** * ** **** 0;
* * ** * ** * ** if(number == 1)
* ** * ** ** ** * * ***** ** * ** *** * 1;
** * ** ** * * ** * * **
* * ** * * * ** * * * * * ** *** *** * fn_num(number-1) + fn_num(number-2);
}

int main()
{
**** ***** * ** * ** ** ** number;
* * *** * ** * * fn;
*** * ** *
* ** * * * * ** ***** **** * * ** &number);
* * * * * ** * **
** ** * * *** * * = fn_num(number);
* * * * * *
* **** ***** ** * *** **** * ** fn);
** ** * *** ** *** ** ***
* ** *** * * ** ***** * 0;
}
trả lời bởi (-193 điểm)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 thích 0 k thích
Hidden content!
#include<stdio.h>
int f(int);

int main()
{
**** * ***** * n;
* * ** ** * * **** ** ***** * * ** ** * * * *
** * *** * ** *****
* * * * *** * * * ** *** * **** f(n));
** ** * ** * * * *
}

int f(int n)
{
* ** * * * * **** * ( n == 0 )
** * ******** ** * *** * *** * * * * * 0;
* * * * **** * * * ** *** if ( n == 1 )
****** * ** * ** *** ** * ** * ** ** * * * * *** 1;
* * ** ** ** * * * *
* *** ** *** * * *** ** *** ***** ( f(n-1) + f(n-2) );
}
trả lời bởi (323 điểm)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 thích 0 k thích
Hidden content!
#include<stdio.h>
int f(int);

main()
{
* ***** * ** ** * * *** n, i = 0, c;
** ** * ** ** ** *** ** *** ****** * ****
* * ** ** **** * ( c = 1 ; c <= n ; c++ )
* * ** * * * **** * * *
* ** ****** *********** **
** *** ** ** * ** *
* *** ******** ***** * * ********* * f(i));
** * * * * ** **
}

int f(int n)
{
** * ***** ****** * * ( n == 0 )
******* * ** * * * * * * * *** * ** 0;
** * ** * * * * * ** if ( n == 1 )
* * * * **** * * *** ** ** *** * ** * 1;
** *** * * ** ** * * * *
* ** * *** * * ** * *** **** ** * * * * ( f(n-1) + f(n-2) );
}
trả lời bởi (323 điểm)
0 0
prog.c:4:1: warning: return type defaults to 'int' [-Wimplicit-int]
 main()
 ^~~~
0 thích 0 k thích
Hidden content!
#include<stdio.h>
int f(int);

main()
{
* ** *** * ** * ** ** n, i = 0, c;
* ** * *** * * * ** ** ** * ** *
***** * * ** *********** ( c = 1 ; c <= n ; c++ )
** * * * ** * * *
* * ** * * * ** **
** * * ****** ** ****
*** * * *** *** * * * *** ****** ** * ** f(i));
** *** **** ** ** * *** * 0;
}

int f(int n)
{
* * * * ** * **** **** ** ** ( n == 0 )
****** * ** * * ** * *** ** ** *** * ** **** ** 0;
*** * *** ** ** if ( n == 1 )
** * ** * * ** * * * **** *** ** *** 1;
* *** *** * **** *
**** *** * ** * * ** * * * * ** * * * * * ( f(n-1) + f(n-2) );
}
trả lời bởi (323 điểm)
0 0
prog.c:4:1: warning: return type defaults to 'int' [-Wimplicit-int]
 main()
 ^~~~
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.6.152
©2016-2024

Những câu hỏi liên quan

0 thích 0 k thích
46 trả lời
[Exercise] Coding (C) - đã hỏi ngày 29 tháng 11 năm 2017 trong Chapter 9: Functions bởi semicolon (5.2k điểm)
ID: 34912 - Xem được từ: 2017-12-14 18:00 - Hiệu lực đến: Không giới hạn
| 1.7k đã xem
0 thích 0 k thích
93 trả lời
[Exercise] Coding (C) - đã hỏi ngày 2 tháng 11 năm 2017 trong Chapter 6: Loops bởi semicolon (5.2k điểm)
ID: 29830 - Xem được từ: 2017-11-02 18:00 - Hiệu lực đến: Không giới hạn
| 2.3k đã xem
0 thích 0 k thích
50 trả lời
[Exercise] Coding (C) - đã hỏi ngày 13 tháng 12 năm 2017 trong Chapter 9: Functions bởi semicolon (5.2k điểm)
ID: 37278 - Xem được từ: 2017-12-14 18:00 - Hiệu lực đến: Không giới hạn
| 1.8k đã xem
0 thích 0 k thích
38 trả lời
[Exercise] Coding (C) - đã hỏi ngày 13 tháng 12 năm 2017 trong Chapter 9: Functions bởi semicolon (5.2k điểm)
ID: 37277 - Xem được từ: 2017-12-14 18:00 - Hiệu lực đến: Không giới hạn
| 1.5k đã xem
0 thích 0 k thích
79 trả lời
[Exercise] Coding (C) - đã hỏi ngày 28 tháng 12 năm 2017 trong Chapter 9: Functions
ID: 39986 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn
| 3.4k đã xem
12,783 câu hỏi
183,443 trả lời
172,219 bình luận
4,824 thành viên