FIBONACI.CPP
资源名称:C++100.rar [点击查看]
上传用户:wszmarenbt
上传日期:2013-04-26
资源大小:2552k
文件大小:1k
源码类别:
Windows编程
开发平台:
Visual C++
- //THE PROGRAM IS TO TEST THE FIBONACCI ORDER LIST.
- //FILE FIBONACI.CPP
- #define CONST 46
- #include <stdio.h>
- #include <conio.h>
- long FIBONACI[CONST];
- long FIBFUNCTION(int NUMBER);
- int main()
- {
- int CIRCLE;
- window(1,1,80,25);
- clrscr();
- for (CIRCLE=0;CIRCLE<CONST;CIRCLE++)
- FIBONACI[CIRCLE]=FIBFUNCTION(CIRCLE);
- printf("nTHE NUMBER FIBFUNCTION(45) IS : %ldn",FIBFUNCTION(CONST-1));
- for (CIRCLE=0;CIRCLE<46;CIRCLE++)
- printf("%ld ",FIBONACI[CIRCLE]);
- //The above limit is "45" && The long integer must less than ten bits.
- //The Fibonacci Order List begins at "FIBFUNCTION(0)=1".
- getch();
- return 0;
- }
- long FIBFUNCTION(int NUMBER)
- {
- long FIB1=1,FIB2=1,FIB3;
- int CIRCLE;
- if (NUMBER<=1) return 1;
- for (FIB3=FIB1+FIB2,CIRCLE=2;CIRCLE<NUMBER;CIRCLE++)
- {
- FIB1=FIB2;
- FIB2=FIB3;
- FIB3=FIB1+FIB2;
- }
- return FIB3;
- }