0 like 0 dislike
2.3k views

(20%)費式數列中,除了第一項第二項是一之外,之後的每一項皆為前兩項的和,請撰寫一程式,由使用者輸入N代表費是數列的第N項,程式會輸出第N項的值。

 

輸入說明:

輸入一個正整數N,代表要計算出費式數列的的N項,N大於0

 

輸出說明:輸出費式數列第N項的值。

輸入範例:
 

5



輸出範例:
 

5

 

[Exam] asked in 2017-1 程式設計(一)AD by (30k points)
ID: 43450 - Available when: 2018-01-19 18:30 - Due to: 2018-01-19 21:30
| 2.3k views

19 Answers

0 like 0 dislike
Hidden content!
#include<stdio.h>
int main()
{
** * ** * ** *** * i,N;
** ** ** ** ** * * ** * arr[500];
**** * * * * * * ** *** * ** *** * ** *
* ** ** ** * * ** * ***** *
* *** ***** ** * * ***
** * * *** * * * * ** **** * * * * * ** * *
    }
* * * ****** ***** *** if(N==2)
    {
*** * * * ** * * * ** ** * * * *
    }
* * *** **** * ** *** if(N>=3)
    {
* * * * *** ** *** * * ** ** * **** * * * * ** * ** *****
** ** * ** * * ** * * ******* * ** * * * *** ** **
* * * * *** * ** ** * ** ** *** ***** * ** *** *** * * * * ** * ***
** * * ***** ** ** *** * ***** *** ******* *** *** ***** ** ** * ******* ** *** *
*** * ** ** * * * ** * *** ** * *** * * * * ****
* ** ** * * ** ****** *** *
* ** ** *** *** * ** * * *** *** *** ** * * *
*** * ** * * ** ** **** ** 0;     
}
answered by (202 points)
0 0
prog.c: In function 'main':
prog.c:6:13: warning: format '%d' expects argument of type 'int *', but argument 2 has type 'int' [-Wformat=]
     scanf("%d",N);
             ^
0 like 0 dislike
Hidden content!
#include <stdio.h>

int cal(int n)
{
* * ** * ** * ** ** *** * * ** **
** ** ** * * * ** ** * * ** * ** * ** n;
* ** ** ***** ** ** ****
* *** * ** *** *** ** ** *** * ** * ******** *** ** ** cal(n-1)+cal(n-2);
}
int main()
{
* * * * *** * * * * ** * n;
* ** * *** ** * * * ** ** ** ********** * **
* * *** * ** * *
*** ** *** * * *** ** ** ** * * **** * * * ** * * ** * * ** *
    }
* * * * * * ** **** * * 0;
}
answered by (114 points)
edited by
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 0
Case 0: Correct output
Case 1: Wrong output
Case 2: Correct output
0 0
Case 0: Correct output
Case 1: Wrong output
Case 2: Correct output
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 0
Case 0: Correct output
Case 1: Wrong output
Case 2: Correct output
0 0
Case 0: Correct output
Case 1: Wrong output
Case 2: Correct output
0 0
-----------Re-judge-----------
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 like 0 dislike
Hidden content!
#include<stdio.h>
int main()
{
** * ** *** * ** * * x,y,n,i,q;
*** *** * ** * * * * ** **** * *
* *** ** * * ** *
* ****** ** * * ** *** **** ****
* ** *** * * * * ** * ****** **
* ****** * ** * * * * *** ** * *** * * **** **** *
* * *** *** * * *   
    {
***** * * * ** * ** ***** **** ***** **** * * *** *** *
***** ** * *** *** * * ** * * * * * * ** *
* * * ** ** * * * * **** * * ** ** * ** ****
* * * ** * * * ******** * * * * * ** * * * **** **** ** * *
* * *** ** ** *** ** *** *** ** ***** ***
********* * * * ** ** * ***** * * * * **
** * ** *** ** * * * ***** ** *** **** *
    }
    
    
}
answered by (172 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
int main()
{
    int x = 1, y = 1, z = 1, n;
* * ** *** ** ** **** ** * **** * * * * *
* ** * ** *** ** **** ** *** * < 2)
* ****** * * **** ** ** * ** * ** * *****
** * ** * *** * * *** **** *
    {
** * * * * * * ***** * ** * * *** * *** * * **** **** * * <= n)
*** * * ** ** ** * * *** * **** ** * ***
* * * * *** * * ** ** * * ** * * * ** * *** * * * *** * * * * * * * ** ** = x + y;
**** * * ** ** *** * ** ** ** **** ** *** * *** ** * ****** ** * ** = y;
*** * * **** * ** ** * * * * * * *** * * * ** ***** ** * * * ****** ** * ** * * **** * * = y+1;
** ** *** ***** **** *** * *** **** **** * * * **
    } * * ** *** * *** * ***
** * * *** * ** ** ** * *** *** ** ** * * * * * * * **
* **** * * * ***** * **** * * ** **    
* * ********* * ** ** *** *** 0;
} * * ** **** * * ******** *
answered by (240 points)
0 0
prog.c: In function 'main':
prog.c:5:13: warning: format '%d' expects argument of type 'int *', but argument 2 has type 'int' [-Wformat=]
     scanf("%d",n);
             ^
0 like 0 dislike
Hidden content!
#include<stdio.h>
int main()
{
* * ** ** ** ** * i,j;
*** ** ** ** * * ** * arr[1000];
* ** * * * * **** * * *
* * * *** * ** * *** ** ** * * *** ** ***
* *** * **** * * * *
* ** * ***** * * ***** = 1;
* ** ** ** *** *** * = 1;
    
* ** * * * * * * *** * *
* *** * * * * *** * * * * = 3;i <= j;i++)
** **** * * * * ****** **
* * * ** ** * * *** ** ***** * ****** * ** * * *** * = arr[i-2] + arr[i-1];
***** *** ** * * ** ** * * *
*** * ** * ***** * * * ** * * * *
** * * * ** ** **** *
** ***** *** ** *** * *
* * * * *** * *** **** 0;
}
*** * * * ***** *** ** ***** * * * *
answered by (212 points)
0 0
prog.c: In function 'main':
prog.c:19:5: warning: implicit declaration of function 'system' [-Wimplicit-function-declaration]
     system("pause");
     ^~~~~~
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 like 0 dislike
Hidden content!
#include<stdio.h>
int main()
{
* ** ** * * * ****** n, i;
* ** * * * ** * * a[1000]={1,1};
* * *** ** ** ** * ** *** ** * * ** *
*** * * * * *** *** * * *** ***
* * * ** * * *** * * * * * * * **
* * * **** * *** ** * * ** * * *** *
** ** * *** ** * **** *** 0;
}
answered by (144 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 like 0 dislike
Hidden content!
* * * ** *
int main()
{
int i,N;
int a[1000];
** * * ****** * ** * * * * * **
* **** * ** *** ** * * *
*
a[1]=1;
**** * **** *
*** ** ***
** ** ** ** ** * * * **** *
* * ** * *


* ** * * * * * * *
return 0;
}
answered by (236 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>
int main ()
{
* * ** *** ** * * x=1,y=1,z=0,n=0;
* * ** ** * * **** *** j;
** * ****** * * ** ** *** *** * *** ** ****
**** *** *** * ** *** == 1)
*** * **** * *** * = x;
* ** * * ** * * * if (n == 2);
**** ** ** * ** * *** = y;
* ** * * ** * * ** (j=2;j<n;j++)
**** * ******** *** ****
*** * ** * **** **** * * * ** * ** * = x + y;
* ** * *** * *** * * ** * * ** = y;
**** *** * * ***** * * ** * *** ** * *** * * = z;
**** * ** ********** *
** ***** *** * ** * ****** * * * *** *****
    
*** * ** * *** * 0;
}
answered by (196 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 like 0 dislike
Hidden content!
#include<stdio.h>
int main()
{
** * * * ** * * a,b,c,d=1,e=1;
* * **** * * * * * **** *** ** * ***
*** ** * * ** * * ** ** *** ** *** ******
* *** * **
* ** *** * * * * * * **
* ** * * * ** **** * * ** }
* * ********* * ***** * * ** * * * *** * *
* * * *** * **** *** * * * 0;
}
answered by (224 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>

int main ()
{
* ** **** * ** **** ** x=1,y=1,z=0,n=0;
** ** ** ** *** **** j;
*** * * ** * * ** * ***** * ** ** ** *
* ** *** ** ** * == 1)
*** ** * * * ** ** * * * = x;
** ** * ** * * *** * * * * ** if (n == 2);
** * * **** **** = y;
** *** ** ***** (j=2;j<n;j++)
* * ** ** ** * * * **
** * ** * * ****** *** * ** ** *** * = x + y;
**** * * * * ** * **** * * ** * = y;
* * *** *** * ****** * * ** *** ** ***** * * ** = z;
** * **** ** * * * ***
* * ******* **** * *** * * *******

**** * * * ** * *** * ******* ** 0;
}
answered by (160 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.58.130
©2016-2024

Related questions

1 like 0 dislike
24 answers
[Exam] asked Jan 19, 2018 in 2017-1 程式設計(一)AD by 楊修俊 (30k points)
ID: 43456 - Available when: 2018-01-19 18:30 - Due to: 2018-01-19 21:30
| 1.5k views
1 like 0 dislike
24 answers
[Exam] asked Jan 19, 2018 in 2017-1 程式設計(一)AD by 楊修俊 (30k points)
ID: 43455 - Available when: 2018-01-19 18:30 - Due to: 2018-01-19 21:30
| 1.4k views
1 like 0 dislike
24 answers
[Exam] asked Jan 19, 2018 in 2017-1 程式設計(一)AD by 楊修俊 (30k points)
ID: 43454 - Available when: 2018-01-19 18:30 - Due to: 2018-01-19 21:30
| 1.5k views
2 like 0 dislike
24 answers
[Exam] asked Jan 19, 2018 in 2017-1 程式設計(一)AD by 楊修俊 (30k points)
ID: 43453 - Available when: 2018-01-19 18:30 - Due to: 2018-01-19 21:30
| 1.4k views
1 like 0 dislike
23 answers
[Exam] asked Jan 19, 2018 in 2017-1 程式設計(一)AD by 楊修俊 (30k points)
ID: 43452 - Available when: 2018-01-19 18:30 - Due to: 2018-01-19 21:30
| 1.3k views
12,783 questions
183,443 answers
172,219 comments
4,824 users