小弟在資訊作業上遇到了一點困難
還請各位大大們協助解惑
謝謝
以下是問題
在費氏數列.c中第18,19,20行可否刪除?不論可否都要詳述為什麼?
if(n==1||n==2)
return 1; //使費式數列的頭兩個數為1
else
以下為費氏數列.c
#include <stdio.h>
#include<stdlib.h>
long long f(int,long long [ ]); //定義一個函數
int main(void)
{
long long cache[50]={0,1,1}; //定義陣列
int n;
scanf("%d",&n); //第幾個費氏數
printf("f(%d) = %I64d\n",n,f(n,cache)); //呼叫函數並印出其值
system("pause");
return 0;
}
long long f(int n,long long cache[ ])
{
if(cache[n]==0)
if(n==1||n==2)
return 1; //使費式數列的頭兩個數為1
else
cache[n] = f(n-1,cache) + f(n-2,cache); //再次呼叫此函數
return cache[n];
}
This entry passed through the Full-Text RSS service — if this is your content and you're reading it on someone else's site, please read the FAQ at fivefilters.org/content-only/faq.php#publishers. Five Filters recommends: 'You Say What You Like, Because They Like What You Say' - http://www.medialens.org/index.php/alerts/alert-archive/alerts-2013/731-you-say-what-you-like-because-they-like-what-you-say.html