0 like 0 dislike
22.8k views

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 Fn = Fn-1 + Fn-2 with seed values F0 = 0, F1= 1

斐波那契數由0和1開始,其後的數就由之前的兩個數相加。用數學表示 Fn = (Fn-1) + (Fn-2),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) - asked in Chapter 6: Loops by (5.2k points)
ID: 29830 - Available when: 2017-11-02 18:00 - Due to: Unlimited

edited by | 22.8k views

93 Answers

0 like 0 dislike
Hidden content!
# include <stdlib.h>

# include <stdio.h>



int fib(int n){


*** * ** *** * ******
** ** ***** * * * ****** * ** ** * * * * * * ** *** * * 0;


*** *** ** * ** * ** * *
*** *** * ** * ** ***** * * * * * ** 1;


* **** * * ****** * * (fib(n-1)+fib(n-2));



}



int main(){



    int input, i;


** * ** **** ** * *** ***




*** **** * * ** * * *** * * ** * * *** * ** * * * * ** &input);


** * * * ** * **** * * *** * *** * *** ** * *** *
* ** * *** * **** * ***** * * ****** ******** * ** * ** ** * * * ** **** cannot less than 0\n\n");


*** * ** ** **** ** * * * *** ** ** *** **
* * ** ** ** *** ***** * ** ** * * * * * *** * *** ** ******** ** ** i<=input; i++)


** * ** * * ** * ** * *** * * * * ** * ** ** * * * ** ** * * * * ** ** ****** ****
** * * ** *** * * * * * ** * ** * ***** ** *** * **** * * * * ******* ** * ** * ** *** **** * *  ", fib(i));
* **** **** *** ** ** * ***** ** * *** ** * * * ** * ******* *** * * **
* * * * * * ** * ** * ***** * * *** * **** * * *



    }


* *** ** ** *** * ** **** ** 0;



}
answered by (-336 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
# include <stdlib.h>

# include <stdio.h>



int fib(int n){


***** ** ** ** * ** * * * *
* * * * * * ** * ***** ** ** **** ***** ** * 0;


** * ** * * * ** ** ** *
* *** * * * ** * **** ** ** * *** *** * * * 1;


* * * * ** * * * (fib(n-1)+fib(n-2));



}



int main(){



    int input, i;


** ** * * * * * * **




**** * * ** ** * * ***** * * ****** * ** * *** *** **** * &input);


** * ** * * * ** ** * ** *** * ** * ** **
* * * * ** * * * * ********* * * * * * * * * * * ** * *** * * *** ** * *** * *** * ** ** cannot less than 0\n\n");


*** ** * ** **** * **** ** *** ****** **** ** * *
***** * * * * **** * ********* * * * * * ** * ** **** **** * * * * i<=input; i++)


** * * * * * ***** *** * * ** * ** * * * ** * ** ** * * *** * * ** * ***** * **
** ****** ** * ** * ** ** ****** **** ** * ** ** ** *** ** ****** * * ** ** ** ** *  ", fib(i));
* ** **** ** * * *** * ** * * * *** ** * ** ** ***** * * ** * * * **** ** **
* * * ** * * ** * *** * ** * * * ** ***** *



    }


* ** *** * ***** * **** * 0;



}
answered by (-336 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
# include <stdlib.h>

# include <stdio.h>



int fib(int n){


** * ** ** ** * *** **
* *** ** * ** ** **** * *** ** * * * **** * 0;


*** *** * * ****** **
*** **** * * ** *** * * * ** ***** **** * * **** 1;


* * ** ******** ** * (fib(n-1)+fib(n-2));



}



int main(){



    int input, i;


* * * * * * ** *** ***




***** * ** *** ** *** ** *** * * * * ** * *** * * ** * &input);


** ** ** * ** * * * * ** ** * * ** ****** ** ** ** * *
* * ** * ** ** *** *** *** * * * * *** * * * * *** ***** ****** * * **** cannot less than 0\n\n");


** ***** * ** * ** * * ** * ** * *** **** * ** *
* * * * * ** *** * *** * ** * ** * * *** ** ** * * ** * ** * * ** i<=input; i++)


** * ** * ** * *** ** * * *** * * *** ** **** ** * * ** * ** * * *** * * ** *** * ** * **
* * ** * ** * *** * ** ********** * *** * * ** * * ** * * *** ** ***** ** * ** *** * ** **  ", fib(i));
* * ******* ***** *** * * * *** ** ** * ** * * *** * * * * **** **** * * * *
* * ** *** ***** * * * * ** ** * * ** **



    }


** ** ** **** * * ** * * *** 0;



}
answered by (-336 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
# include <stdlib.h>

# include <stdio.h>



int fib(int n){


* * * * ** ***** *** *
** ** **** **** ** ** * * ** *** * * ** * 0;


* ** * ***** *** * * *** ** ****
* * * * * * * ** * ***** * * * **** ***** ****** 1;


******* ** ** * **** * (fib(n-1)+fib(n-2));



}



int main(){



    int input, i;


* * ** * * * ** ***




** * * ****** ** * ***** * ** * * * * ** * ** ** * **** * * * * ** &input);


* ** *** * ** * * *** ** * ** ** ** * **** ***
* *** * * * *** *** * ** * * *** * * **** **** * * *** *** cannot less than 0\n\n");


* ** * * * * ** * * * ** **** ** * **
** *** ** * * * ***** * ** * * * ** * * *** ** * * ** * * * * * i<=input; i++)


** * * * * * * *********** ********* ** * * ** ** * ***** * * * * ** * * *** * ** **
*** * * *** * ***** * * *** * * ** ** **** *** * * ****** * ** ** * ** * *** * * ** **** *****  ", fib(i));
* ** ** ***** *** **** ** * * * ****** ** *** ** ****** * * * * * **** * ******
** * ** * ** **** ** ** *******



    }


** ** ** **** ** ****** 0;



}
answered by (-336 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
# include <stdlib.h>

# include <stdio.h>



int fib(int n){


*** * * ** ** * * ** * * ****
** * * * * * ** ** * ** ** ** ** ** * * * 0;


* * **** * * ** * ** * * *
** *** * * *** **** ***** * * *** * * * 1;


* * * ** **** * * * * (fib(n-1)+fib(n-2));



}



int main(){



    int input, i;


**** ****** * * **** **** *




*** * *** **** * * *** *** *** ** ** *** **** ******** ** * * *** &input);


**** * ** ** **** * * *** ** ** * ** * ** **** ** **
** * ***** ** *** * * ** ********* ** **** * ** * * *** *** cannot less than 0\n\n");


* ** ** ****** * **** ** ** ** *** * ** ** *
* **** ** * ** * * ** *** * * ***** * * * * ** * * ** * i<=input; i++)


** * *** * *** * ** * * ** * * ** ** ** **** **** * ** ** * * ** * **** * * *** * ** *******
** * ** ** **** * * *** *** *** * * * * * *** **** ** * ** * ** * * *** * **  ", fib(i));
** * * * ** * *** * * * ****** ** * ** ****** * *** ***** * *** * * * * *** *
* ** * * ** ** * * * * * * ** * **



    }


** **** ** ***** ** **** 0;



}
answered by (-336 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
# include <stdlib.h>

# include <stdio.h>



int fib(int n){


** * * * **** * ********
* *** ** **** *** * *** ** *** ** * ** ** * * 0;


* ** * * ******** * ** ** ******
* * * *** * ** * *** * * ***** *** **** * *** 1;


* * **** * * * * ** ** *** (fib(n-1)+fib(n-2));



}



int main(){



    int input, i;


* ** **** * *** **** * * **




** * * * * * ** * * ** ** * ** *** ** ** ** * ** * **** ** * &input);


** * ** *** * ** * *** * ** *** *** ** * * *
***** ** * **** **** ** ** *** ** * ** *** ** ** * *** * * ****** * *** * *** cannot less than 0\n\n");


** * *** *** * * * *** ** ********** **
* *** * * ****** * * * * * ***** ** * ** * * ** *** i<=input; i++)


* * ** * **** ** **** ** * * * * * ** **** * * * ****** ** *** * *** *** * * ** ** ******* * **
* *** * ** * ** ** ** * **** * * * *** * ** * ***** * * ** ** * * * * *** ***** ** **  ", fib(i));
* *** ** *** * ** ** *** * ** * * ** * * * * * * ** ***** ** ** *** ** *** ** *****
* ***** ** ****** ****** **** ** * ** **



    }


* ** ** *** *** * 0;



}
answered by (-336 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
# include <stdlib.h>

# include <stdio.h>



int fib(int n){


* ** * * * * *****
** * * *** * * ** * * **** * ** **** * * 0;


* * * * * *** * ** *
** ** ** ******* * * ******* **** ** * * * * 1;


** * * * *** **** * * * (fib(n-1)+fib(n-2));



}



int main(){



    int input, i;


* ** * * * * ** *




* ** * * * *** * * * *** * *** * *** ***** ******* ** ** &input);


*** ** * ** * **** * *** ** * * * * ****** *
* * ********* * * * * **** ** ** * ***** ** * * ** ******** ** * * * * * * ** cannot less than 0\n\n");


* **** *** * ***** * ** ***** ** *** *
* ** *** * * *** ** * *** ***** *** * **** * ** **** * ***** i<=input; i++)


* * * * * ** ** ** *** * * **** ** * ** * ** * * * * * **** ** **** *** * * **
* * * * *** * *** * *** *** **** * * * ** * *** * * * ** * * ** *** ** ***** ******** *** **  ", fib(i));
* ** * * ** * * **** * * ** * * * *** * ** *** * ****** *** * * ** * * ** * * ** *
* * * *** ** ***** * * * * * ** * ***



    }


***** * ** * * 0;



}
answered by (-336 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int num = 0;

* *** **** * *** ** * ** *** * *** * &num);

*** * ** ** * * ** * * * == 0)
*** * **** * ** * * * *** **** *** * * * ******** ** * *
** * * ***** * * * if(num == 1)
* ** * ** *** *** * *** * * ** * *** ** * * ** *****
***** **** * *** * ** ** if(num == 2)
** * ** *** * * *** *** * * * * **** * * * ** ** *
** * ** * ****** *** * if(num == 3)
** ** *** * * *** ** *** ** * * ** **** * *
    else if(num == 4)
** *** ** *** ** *** * ****** * ** ** ***** * * ** * ** * ** **
** * * ** *** * ** if(num == 5)
* *** * * * ****** * * * ***** * * * ** * **
* * *** * * *** * if(num == 6)
****** **** *** * ** ***** ** * *** ** ** ** * * ** * * *
* ** ** ****** **** ** * if(num == 7)
* ** ** ** ** * ** * *** * * * * ** * * ** ** * *** ** *
* ** ***** ** * ** ** * ** * * * if(num == 8)
** * ** * * *** ** * * * * **** ** *** ** * * ****
*** * *** ***** ** ****** * * * if(num == 9)
** *** * *** ** * * *** * *** ** ** * * * * ** * ****
* ****** ***** ** * * *** * if(num == 10)
*** *** * * ** ** ** * **** * ** * * ** ***** **
    else if(num == 11)
* * ** ** * * *** * * * ******* ** * * * * *
    else
* **** * *** ***** * **** * * ****** * * * * **** * *

** **** ** * ** *** * 0;
}
answered by (-285 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
Hidden content!
#include<stdio.h>
int main(void)
{
** * * * ** * ** * * *** * * ** * ** * * n,i;
*** * * ** **** * * * * * * * ** ** tab[100];
* ****** **** * ** * *** ***** * * *** * *** ** * * * * *
*** * *** **** *** * * * * *** * **** *** *
* * * * * * * * ** ** * ** ** * ** * **
*** ** **** ** * ** **** ****** * ** * * *** ** (n==0)
        {
*** ** * *** * ** *** **** **** ****** ** * * * * *** ** * * * * *** * * *********
* * * ** * * ** * **** *** ** * ***
* ** **** * * * * * * **** * * * (n==1)
*** *** * *** ** * * ** *** * * * ** * * *
** * ** * * ***** * * ** *** *** * *** *** * *** ** * ***** * *** * ** * *** * * * *
        }
** * ** ***** * * *** * *** * * * * ** *** && n!=1)
* * * * ** **** * ** ** * *** *** * * * *
* ** *** * ** * * *** * ** ** ***** (i=2;i<=n;i++)
** * * *** * ** * * ** * * * *** * * ** ** ***
** ** * ** * * ** * ** * ** ***** ** **** *** *** **
* ** * ** ** * * * * * * **** * * *** **** *
** ** * *** * * * ** * * **** ** * * *** * * ***** * *** ***
        }
****** * * ****** * * ** *** * **** ** * ** * ** ** 0;
}
answered by (-168 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
int main()
{
* * ***** * *** * i,n,a,b;
* * ***** ********* * ** * * * * ** * * &n);
* * * ** * * ***
* ** * * * * *** * *
* * ** *** * *** ** ( i=1;i<=n-1;i++)
* * ** * ** ** * * * ** *
* * * * * * * * * * * ***** ***
** ** * * ** ** * ** ***** * * ***** * * ** ** * *** *** * **
* ** ** * *** ** * * * * * * * * * * *** ** *** ** b=b+a;
* ** ** *** * *** *** *
** * * * ** ** ** ** ****** * ** * n%2==0 ? a : b );
**** ** ** ** * * * ** * 0;
}
answered by (-196 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:162.159.115.9
©2016-2026

Related questions

0 like 0 dislike
46 answers
[Exercise] Coding (C) - asked Nov 29, 2017 in Chapter 9: Functions by semicolon (5.2k points)
ID: 34912 - Available when: 2017-12-14 18:00 - Due to: Unlimited
| 14.6k views
0 like 0 dislike
99 answers
[Exercise] Coding (C) - asked Nov 2, 2017 in Chapter 6: Loops by semicolon (5.2k points)
ID: 29829 - Available when: 2017-11-02 18:00 - Due to: Unlimited
| 26.6k views
0 like 0 dislike
41 answers
[Exercise] Coding (C) - asked Dec 14, 2017 in Chapter 9: Functions by semicolon (5.2k points)
ID: 37370 - Available when: 2017-12-14 18:00 - Due to: Unlimited
| 11.3k views
0 like 0 dislike
72 answers
[Exercise] Coding (C) - asked Nov 2, 2017 in Chapter 6: Loops by semicolon (5.2k points)
ID: 29831 - Available when: 2017-11-02 18:00 - Due to: Unlimited
| 18.1k views
2 like 0 dislike
67 answers
[Exercise] Coding (C) - asked Nov 9, 2017 in Chapter 6: Loops by semicolon (5.2k points)
ID: 31048 - Available when: 2017-11-09 18:00 - Due to: Unlimited
| 18.4k views
12,783 questions
183,442 answers
172,219 comments
4,824 users