斐波那契实在是个很有趣的东东…… 下面这个程序是很久以前编写的了,号称斐波那契的线性算法。其中使用了线性规划,第一次是在weiss的书上看到的,就写出来了。 但风格不太好,我不喜欢这样的风格。 #include <stdio.h> int Fib(int N){ //斐波那契数列的线性算法 int i; int nexttolast,last,answeer; if(N==0) return 0; else if(N==1) return 1; else{ nexttolast=0; last=1; for(i=2;i<=N;i++){ answeer=nexttolast+last; nexttolast=last; last=answeer; }//for return answeer; }//else }//fib void main(){ //驱动例程 int N; puts("Give the number and I will give you answeer..."); scanf("%d",&N); printf("You type the %d, and the answeer is %d/n",N,Fib(N)); }//main