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 Fn = Fn-1 + Fn-2 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
edited | 731 views

## 93 Answers

0 like 0 dislike
`Hidden content!#include<stdio.h>int main(){*** *   ***   *    ***   F0,F1,Fn,n,a;** * * **  *****    ** * ** ** * *  **  ** * * ** * * **  * * *    ** **   * **   * &a); * *   *  * *** **  * ***** *  ****  *     * **** **  * * *    *   **  ** * **  *      * ********* **  *   *      ** * *    ** *    * ***  **  *  *  *  *  * * ********   *** *    *   * * * **   ***    ** *** ***  *** * *   ***** **  * *    *  * ** ****    }**   ** *   *   ** *  *     * * **  *  *   Fn);  **     ***   **    ***** ***   0;}`
answered by (-32 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  *** * * *  *int *  *  *{int  * *   * *****      * * ******* ** ** ** if(a==0) printf(0);else if(a==1) printf(1);else {** * *   *****   **      *** * *   ****     ***   *  * * ***    **  **** * **  **** *  *  ** ***      = c0+c1;***  *   * ** *** ****  ******* * **  **  ** *********   *** * * = c1; **      *      *****  * **    *   *    **  ***  * ** *** ** = cb;*  ***** * ** *   ***** ***  *  **** * * ***** *** *** *** ** *** * * ** *   ***  * *}return 0 ;}`
answered by (-254 points)
0 0
prog.c: In function 'main':
prog.c:6:10: warning: null argument where non-null required (argument 1) [-Wnonnull]
if(a==0) printf(0);
^~~~~~
prog.c:7:22: warning: passing argument 1 of 'printf' makes pointer from integer without a cast [-Wint-conversion]
else if(a==1) printf(1);
^
In file included from prog.c:1:0:
/usr/include/stdio.h:364:12: note: expected 'const char * restrict' but argument is of type 'int'
extern int printf (const char *__restrict __format, ...);
^~~~~~
prog.c:7:1: warning: format not a string literal and no format arguments [-Wformat-security]
else if(a==1) printf(1);
^~~~
0 like 0 dislike
`Hidden content!#include * * ****  ** *int      *  {int **     **   *  ****  * **  * ********** *if(a==0) printf(0);else if(a==1) **     else {** * **   ******  * * *  *       *** *** ** *  ***    *******     * *** ** ****    *** **  ** *   **   **   ** *  * * = c0+c1;* * ** ** *** * *  * **  **   * *  **    **   * *** = c1; *    *  ******  ** * ** *** *** * ** ** ***  ***** *  * = cb;*  *  **   ****  ** **    **  **  * * *   *  * ***  * *  * ***  ** **** * *    *   *      ***}return 0 ;}`
answered by (-254 points)
0 0
prog.c: In function 'main':
prog.c:9:10: warning: null argument where non-null required (argument 1) [-Wnonnull]
if(a==0) printf(0);
^~~~~~
prog.c:10:22: warning: passing argument 1 of 'printf' makes pointer from integer without a cast [-Wint-conversion]
else if(a==1) printf(1);
^
In file included from prog.c:1:0:
/usr/include/stdio.h:364:12: note: expected 'const char * restrict' but argument is of type 'int'
extern int printf (const char *__restrict __format, ...);
^~~~~~
prog.c:10:1: warning: format not a string literal and no format arguments [-Wformat-security]
else if(a==1) printf(1);
^~~~
0 like 0 dislike
`Hidden content!#include *******  **     int main(void){int  *  *  * * * **    **    *** **    *******if(i==0)   * *** * **  * **else if(i==1) * **    * *  * * *****  *else {** *  ****** ***  *   *  *  *   *****  *  *   *** *** *  ******  *  * ****   *  *** * * *** **     **      = f0+f1;  ** ***   **    *   * ***** *** ** ***  **  *****  * * ** = f1;* *  *    ***  *  *     **  **  *   *****   ** ** * ** * = fn; * * * ** ** ***    * *    *** ** **    *  ****  * *  **   ** *  * *    **   **}return 0;}`
answered by (-107 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     ***    * **int **    *{int    **     **** * **  *** ** * *      if(i==0) printf(0);else if(i==1)  ****else {*** **  * **  *  *  * *****   * ** ** *  **** * * *    *** * **  * ****  **  * **   *  **** *    * **  *** = f0+f1;*    **    ** **    **  **** **      *  * *   *  * = f1;   *  * **  **  * *    **  **** * *** * ** * * **** = fn; *** *  *  * * ** ** ***  * *    **      **  * * **     **   **   *  ****   }return 0;}`
answered by (-107 points)
0 0
prog.c: In function 'main':
prog.c:9:10: warning: null argument where non-null required (argument 1) [-Wnonnull]
if(i==0) printf(0);
^~~~~~
prog.c:10:22: warning: passing argument 1 of 'printf' makes pointer from integer without a cast [-Wint-conversion]
else if(i==1) printf(1);
^
In file included from prog.c:1:0:
/usr/include/stdio.h:364:12: note: expected 'const char * restrict' but argument is of type 'int'
extern int printf (const char *__restrict __format, ...);
^~~~~~
prog.c:10:1: warning: format not a string literal and no format arguments [-Wformat-security]
else if(i==1) printf(1);
^~~~
0 like 0 dislike
Hidden content!
#include<stdio.h>

int main ()

{

int a,b,n,e=0;
* *** ** * ** * *** * * * * ** ** ** %d", &a,&b);

for (n=(a+1); n<b; n++)

{
* *** **** * *** * ** * * * ** ***** d;
* * **** ** ** * * * **** * * * * * *** (d=2; d<n; d++)
** * * *** ** ** * ** ** * * ***
** * *** * * * * ** * * ** * * * * * * * * (n%d==0)
*** *** * ***** *** * * * * ** ** ** * * * * ** * **** * *** ** ** *

}
* **** ** * ** * * ** * **** * * * ** ** **
** ** **** **** * ** ** * ****** ****** * *
****** ** * * * * * *** ****** **** * **** * * * **
* ** * * ** **** *** * * ** * * *
* ** *** * ** ** * * * * * * * **** * ** * * * * *** *** * (e==0)
* *** * ** *** *** ** *** ** ** ** * * *** * ***** * * * * * ** *** **** * *
* **** * * ** ** ***** ** ** * ** * ** ** ** *** * * **** ** *
* * ***** * ** * ** * * **** * ***** * ** **** **** ** *** ** ** **** **** ** ****** * **** ** ");
* * * ** ** *** **** * ** * ** * *** * **** * * * * * * * * ** * ** ** *
* ** **** * * *** ** ** * **** ** ** * *** ** * ******** * * ** * ** *** * ******
** * ******* * * ** *** * * * * * * *

}

return 0 ;

}
answered by (-254 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>

int main ()

{

int a,b,n,e=0;
* * * ** ** ***** ** * **** * * ** * ** %d", &a,&b);

for (n=(a+1); n<b; n++)

{
******** ** *** **** *** **** * * ** *** ** * ** ** d;
* * **** * * * * * *** *** ** * *** * *** * ** * * (d=2; d<n; d++)
* * * * * *** * ** ** ** ** * * ***
***** * *** * * * *** * * * * * ** * (n%d==0)
* *** * *** ** * ** * * ** * ** *** ***** * * * *** *

}
* **** ** ********* *** ** ** * * *
** ** * ** * * ** ** * * **** * ** **
* *** * ** * * ******* ****** * * * *** * *
* ***** * ** * * * * **** * **** ******* **
* ** ** ** * * * * ****** * * ** * ****** * * **** ** * * *** (e==0)
***** *** *** * * *** ** ** * ** ** *** * *** ** * **** ** * ** * * * ** * ** ** * * ** *
*** * ** ***** ** * ** * ** * ** ** * **** *** * * *** * * * *
* ** ****** * * * * * * *** ***** * *** * ** * ** ** * *** * ** * * * *** *** *** * * * ** * ");
** * * * * * * *** ***** * * **** ** * * ** ** **
**** *** *** ** ** * * * ****** **** * * * * **** * ** ** * ** * *** * **
*** * * ** * ***** * *** * ** **** ** *** *

}

return 0 ;

}
answered by (-254 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>main (){    int a,b,n,e=0;    scanf("%d %d", &a,&b);    for (n=(a+1); n<b; n++)    {**  *  * * ****** **   *  * ** * * **   *   * * *******  * d;*  * **  * **    *     **     ****     *** ***   *  ***  **  (d=2; d<n; d++) *  *    **  **   ** * ******   ** *** ***    * * **     *   *   *      * ******      * **** *    *  **       (n%d==0)**       *    ****** * *    **  * ******** * **     *   ** * ***** * ** *******  *** *   }*  * ******** *    ***   *       ***    *   **  **  * *  * ******  *    * * * *     *   **** *  *** ****  *     * **   *    *    *  * *  *      ***      * **     ****    * **     **  *** * * ****  ***  * ********* *   * * *  **** **** ***   *  * * * *     ** ***    * *  * * * * **** * ** * * * **  * *  * *    ***      (e==0)**** **     *    * *  * ** * **   * **  **** *     * *  **** * ******  *  * * ****** * * *    ******      ***** *  *****  * *  * **    * *  **   * **  ****** ***    * ***      ** *   ******  * ***  * **  * ** **     *    * *  * *      * * ****  *  * ** * *  *    **  ** ** * *    *    ** * * **** *  * * **      **  ");   * **   * ***     **** *  ** *  **  **   *** ** ** *  *  *      * ****  * *  * * *****  * * **  *  * ***** ***  * *  ** ** **   ***  * ** *   *****    ** ** *****   *     * *   * **** *** ***   ** ** *    ** * **   ****     *** *** *}return 0 ;}`
answered by (-254 points)
0 1
prog.c:2:1: warning: return type defaults to 'int' [-Wimplicit-int]
main ()
^~~~
0 like 0 dislike
`Hidden content!#include <stdio.h>int main(){* ** * * **** *  ***   ******     Fn,t1=0,t2=1, n,input;   *     **   **  * ** * *  ***** *  **   **** ***** ** ******** * *  * * ****  * * *  *********   *     n++)   *      *     ***********       *** ** *** ** *      *  ** * * *   ***** ** ***    **** * = t1 + t2;  * * ***  ** * **     *****   ****    *** * *  * * *** **      * * ****** * ** ***** * * **   ** ** **** * ** ******       } **     ** *   ** ***  * * ****  ** * * ****   ******  * *  **   * ** ** 0;}`
answered by (-281 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(){**   * **    ******  *  *  Fn,t1=0,t2=1, n,input;       *   *******   * ***    * ****** ** ** *  * **    **  * **** *******  ** * * ** *  **  * ***  n++)* * **** * ** * **  ** * ***      ***   ****      ** ***  ** *******  *** *   * * = t1 + t2;** * **  **  * *   *******  **   *   * **  **  *  **    *   ***  * ****** ** *          ** * ** ** ****  * * **      * *  * *   **  ** * *    * *   ******  *  *** * * * ** * ****  ",Fn);     *******   * * * ***  *  0;}`
answered by (-281 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output