0 like 0 dislike
3.8k views

Please use array. 請使用陣列

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) - asked in Chapter 9: Functions by (5.2k points)
ID: 34912 - Available when: 2017-12-14 18:00 - Due to: Unlimited

edited by | 3.8k views

46 Answers

0 like 0 dislike
Hidden content!
#include ** ** ** *

int main()
{
**** ** * * * ** ** *** * ** i,n;
* ** *** * * ** * * * * * * * * * * **
* ** * * * ** * * f[40]={0,1};
** * * * * ** * * * * (i=2;i<=n;i++)
* * ** * * *** * * * * * *** ****
* * * * * **** ** *** * * * ** * * ** ** * * *
** *** *** *** * 0;
}
answered by (-249 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!
** **** * **** **
int main(void)
{
** * * ****** ***** *** a[999]={0,1},b,c,d;//c=total amount
* ** * *** * **** ***** * * * * ** * * **
* **** * ***** ** * * ** * ** **** ** *** (d=2;d<999;d++){
***** * * * * ** * ** ** *** ** ***** * * ** * * ** *** * * **** * ***
** ** * * **** * ** **** ** * **** ** * *
** * **** * * ****** ** * * ***** ** **** * ****** ("%d",a[c]);
}
answered by (-204 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!
** * * * **
int main(void)
{
* * ****** * ** * ** ** a[999]={0,1},b,c,d;//c=total amount
* *** *** *** * * ******* ** ** ** ** * ***
*** **** * ** * * ****** * * * *** * * * * *** (d=2;d<13;d++){
** ** ** **** * ** * * ** * *** *** ** **** ** ** * * * * * * ** ** *** * * *** *** ***
* ** ** * ****** * ******** * **** * *** *
** * * ** **** * * ** * *** * ** ** ** * * * * ("%d",a[c]);
}
answered by (-204 points)
0 0
Case 0: Wrong output
Case 1: Correct output
Case 2: Correct output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>

int main (){
    int a,c;
* * * * * ****** * ** * **** ** * * * ****
    if(a!=0){
****** * ** * * * * ** **** *** * * *** b[a];
* ** * *** ** * * ******* * **** **** * * *
***** * ******* * * *** * * * * * * * ** *
*** * ** **** * *** ** **** * * * ****** * ** * *** ** ** *
** **** * * * * ** ** * * * ** **** * * ** **** *** ** * ** ** *******
* ** * * **** * * **** ** * *** ** * **
* ** * *** * ** * * ** *** ** ** *** * * **** ** * **** * **
**** * ** * ** * * ****** * ** * *
    return 0;
}
answered by (-498 points)
edited by
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
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 ** *** ** *
#include **** * *

int main()
{
* i,N;
** ** * * * ** * * * ****
* *** * ****** a[N];
* * ** * **** *
* ********* ** **
** ** *** * * * i<=N; i++)
* *******
** * * ** * * ** ** ***** *****
* ** * ** *** * ***** * ******* * * **
  }
* * * * * * *** * * * **** * * **  
******* **** * * 0;
}
answered by (-108 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 ** **
#include ** * *

int main()
{
* ** i,N;
* * * ** * ** * ** *** **
* *** * ** a[N];
* ** * *** *
* ** * * **
****** ****** * i<=N; i++)
** * ** ***
** ****** **** *** ** * *
**** * * ** ** ** **** ** * * * * ** * * *
  }
* ** * ** **** ** **  
* *** * **** *** 0;
}
answered by (-284 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()
{
** ** ** ** * ** ** * * n;
* *** ** *** * * ** j;
* * * ** ** * * ** * * ** * * * * ***** *
**** ** * * * ** * ** * c[n];
*** ** * * ** * ** *
* * * ******** ** **
*** * ** *** * * *** ** ***** ** ***
* * * * *** * ** * * *** *** ** * ** ** ** printf(" *%d\n",j);
* ** * *** * ** * * * ** ** * * * ***** *
* ******* * *** *** ****** ** * * *** ** * * * * ** * ** * * *
    }
*** **** ** * * * * *** * * * *** **** *
*** * * * ** *** **** 0;
}
answered by (54 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 main()
{
*** ** * ** ******** *** *** * *** i = 0;

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

* ******* * ** ** * * **** array[i];

* *** *** *** ** ** *** j = 0;

* **** * * ** * **** * * * = 0;

* *** ***** ** *** ** *** * * = 1;

***** *** ** * ****** * ** = 2; j <= i; j++)
**** * *** * * * **
* * ** ** ******** ** ** ** *** * * * ** *** * * ** **** = array[j - 1] + array[j - 2];
** * *** * ********* *** * *

** * *** *** * * ** * * ** * **** * array[i]);

}
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 ** * ***

int maim()
{
** * * ******** ** ** * * ***** * i = 0;

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

** ** * *** *** ** * ** array[i];

** ** * *** * * **** ** j = 0;

* * ** *** *** * * * * ** = 0;

* * * ** ** * * * * ** * = 1;

******* * * * * **** ** ** = 2; j <= i; j++)
*** ********* * ** *
**** * * * **** ** ***** ***** **** * **** = array[j - 1] + array[j - 2];
** * * **** ** * *

*** * ** ** * **** ** ** ** ** * ** *** array[i]);

}
answered by (-285 points)
0 0
/usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
0 like 0 dislike
Hidden content!
* * *** ***** * ** * i = 0;

* *** * * **** * * * ** *** ** **** * * &i);

* *** ** ** * * * * array[i];

* ** *** * * * ***** j = 0;

**** *** *** * * * **** * * = 0;

** *** * **** ** * * = 1;

* ** * * ** ** * ** *** = 2; j <= i; j++)
** * * * ***** * *****
* * ** ** * *** ** * ****** ** ** *** * ** * ** = array[j - 1] + array[j - 2];
******* * * **** *** **

*** * ****** * ** * * ** ** * array[i]);
answered by (-285 points)
0 0
prog.c:3:11: error: expected declaration specifiers or '...' before string constant
     scanf("%d", &i);
           ^~~~
prog.c:3:17: error: expected declaration specifiers or '...' before '&' token
     scanf("%d", &i);
                 ^
prog.c:5:9: error: variably modified 'array' at file scope
     int array[i];
         ^~~~~
prog.c:9:5: warning: data definition has no type or storage class
     array[0] = 0;
     ^~~~~
prog.c:9:5: warning: type defaults to 'int' in declaration of 'array' [-Wimplicit-int]
prog.c:9:5: error: conflicting types for 'array'
prog.c:5:9: note: previous declaration of 'array' was here
     int array[i];
         ^~~~~
prog.c:9:16: error: invalid initializer
     array[0] = 0;
                ^
prog.c:11:5: warning: data definition has no type or storage class
     array[1] = 1;
     ^~~~~
prog.c:11:5: warning: type defaults to 'int' in declaration of 'array' [-Wimplicit-int]
prog.c:11:16: error: invalid initializer
     array[1] = 1;
                ^
prog.c:13:5: error: expected identifier or '(' before 'for'
     for(j = 2; j <= i; j++)
     ^~~
prog.c:13:18: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<=' token
     for(j = 2; j <= i; j++)
                  ^~
prog.c:13:25: error: expected '=', ',', ';', 'asm' or '__attribute__' before '++' token
     for(j = 2; j <= i; j++)
                         ^~
prog.c:18:12: error: expected declaration specifiers or '...' before string constant
     printf("%d", array[i]);
            ^~~~
prog.c:18:18: error: expected declaration specifiers or '...' before 'array'
     printf("%d", array[i]);
                  ^~~~~
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.70.126.28
©2016-2024

Related questions

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
| 3.2k views
0 like 0 dislike
93 answers
[Exercise] Coding (C) - asked Nov 2, 2017 in Chapter 6: Loops by semicolon (5.2k points)
ID: 29830 - Available when: 2017-11-02 18:00 - Due to: Unlimited
| 6.6k views
0 like 0 dislike
55 answers
[Exercise] Coding (C) - asked Nov 29, 2017 in Chapter 8: Arrays by semicolon (5.2k points)
ID: 34968 - Available when: 2017-11-30 18:00 - Due to: Unlimited
| 5.3k views
0 like 0 dislike
56 answers
[Exercise] Coding (C) - asked Nov 29, 2017 in Chapter 8: Arrays by semicolon (5.2k points)
ID: 34913 - Available when: 2017-11-30 18:00 - Due to: Unlimited
| 4.6k views
0 like 0 dislike
47 answers
[Exercise] Coding (C) - asked Dec 7, 2017 in Chapter 9: Functions by semicolon (5.2k points)
ID: 35785 - Available when: 2017-12-07 18:00 - Due to: Unlimited
| 3.7k views
12,783 questions
183,443 answers
172,219 comments
4,824 users