0 like 0 dislike

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

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

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

Example input 1:

``5``

Example output 1:

``5``

Example input 2:

``12``

Example output 2:

``144``

[Exercise] Coding (C) - asked | 543 views

0 like 0 dislike
`Hidden content!#include **   * *  ** *int F(int n){*    ****   *       *          * **** * *      * *      * * 1;     * *  * * *     ** *** * ***    *   *  *   * ******   0;  * * * *   **    *  *  ** *  F(n-1)+F(n-2);}int main(void){ *  *  * * ******** *   ** n;  ******  ***   * * * * * *      **    ***  ***  * *   *    * **  *   *  ****    *   * *********    *** ** * * *    *  *     0;}`
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  * ** * *** *  *int F(int n){***  ***   * * ***   *   *    **  **   * ** ** ***      *  1;***  ** *  *****  *  *** **       *   **  **  ****   *** *  0;  * *   **  *  *      *     F(n-1)+F(n-2);}int main(void){ * ** *   ***  *  *  ** n;       **  ** **    * *** ****** * *    ** *   *  * * ** ** * *** *  *** * *  **  *** *  * **   ** ***** *  * *  **  *  0;}`
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
`Hidden content!int F(int n){**  *    ***  * * * * * *   ***     ***  *  *    *   1;*   * **  **** ** **     * ***  ** **  * *** *   *  * 0;*    *     * * *   * *  * F(n-1)+F(n-2);}int main(void){* *   ** ** * ******  * * n;****** *   *  *** ** **  *** **  * *** **     ********    *    ** * **      ** * * ***  *    ** **** * * * * ***   0;}`
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 like 0 dislike
`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));    }}`
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 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));    }}`
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 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));    }}`
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 *      **  ** * 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;}`
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 f(int);int main(){* ** ** * * **  ** ** * *  ***** n;  **  *  * * *****  ***    ****  ******  * ****  * ****  ** ***   * ** * ***** * *** * * **   ** * **     * **** ***  *   * **** ** *** f(n));* ** ** ***  * **   *** }int f(int n){** *  ** ******     * ** *  ( n == 0 ) ***  **     ***** * * *   **   * * **  * * **  *   **** ****  ** 0;*    **  ** * ** ***  ** if ( n == 1 )     * **    ** **** **   **   *** *  ***   * ***      * 1;* ** ** ** ** **** **    *  ***   * * *** * ***** *****  *** ***   * **  * **  ** *****   ** ( f(n-1) + f(n-2) );}`
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 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) );}`
`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) );}`