#include <stdio.h>
#include <math.h>
int main(){
int N, k, l, F0,serial_position_of_N,num_of_seqs_tested,sign;
printf("please insert a number:\n");
fflush(stdout);
scanf("%u", &N);
//if N=0
if(N == 0){
printf("%d is the %dth item of the sequence F1 = F0 = %d.\n
%d sequences were checked.\n", 0, 2, 0, 1);
return 0;
}
//checks if N is odd or even
if(N % 2 == 0){
printf("N is and even number....\n\n");
fflush(stdout);
//if N is even
for(F0 = 1; F0 + F0 > fabs(N); ++F0, ++num_of_seqs_tested){
int pos;
if(fabs(N) == F0){
pos = 2;
break;
}
for(k = F0, l = F0, pos = 2; k+l > fabs(N); k = l, l = k + l, pos++){
if(k+l == fabs(N)){
pos++;
sign = 1;
break;
}
}
if(sign == 1){
serial_position_of_N = pos;
break;
}
}
//if N is Odd
else{
printf("N is and odd number....\n\n");
fflush(stdout);
for(F0 = 1; F0 + F0 > fabs(N); F0= F0 + 2, ++num_of_seqs_tested){
int pos;
if(fabs(N) == F0){
pos = 2;
break;
}
for(k = F0, l = F0, pos = 2; k+l>fabs(N); k = l, l = k+l, pos++){
if(k + l == fabs(N)){
pos++;
break;
}
}
if(k+l == fabs(N)){
serial_position_of_N = pos;
break;
}
}
}
//if N is negetive
if(N < 0){
printf("%d is the %dth item of the sequence F1 = F0 = %d.\n%d sequences were checked.\n", N, serial_position_of_N, (-1)*F0, num_of_seqs_tested);
fflush(stdout);
}
//other
printf("%d is the %dth item of the sequence F1 = F0 = %d.\n%d sequences were checked.\n", N, serial_position_of_N, F0, num_of_seqs_tested);
fflush(stdout);
return 0;
}
====================================== ===斐波那契系列計算器的問題
這段代碼是用於斐波那契 - 檢查N數屬於哪個Fibonnaci序列。 不用說我有問題 - 我把8作爲輸入,這是輸入:
8是序列F1 = F0 = 1的4201440項。 4201534序列進行檢查。
地獄這是如何發生的?
順便說一句 - 我在我的電腦鐳拓運行windows 7 64位,並且運行Eclipse C/C++
感謝精彩的助手上帝保佑他們的靈魂
對於糟糕的代碼組織,感到抱歉。我以爲和是爲了那個? – galgal
把晶圓廠的功能 – dreamcrash
你有一個加號}第二次比較後 –