Вы находитесь на странице: 1из 1

Program 2: Program to print the golden ratios of Fibonacci Series PROGRAM SOURCE: #include<iostream.h> #include<conio.h> #include<stdio.h> #include<math.

h> #define N 50 int main() { int a=0,b=1,c,i=0,j=0; float gr[N],div[N],ans[N],dif=1.0; clrscr(); cout<<"\n Program to print the golden ratios of Fibonacci Series"; cout<<b<<endl; do{ //determine the elements in the Fibonacci Series c=a+b; gr[i]=c; a=b; b=c; if(i>0) { div[i]=gr[i]/gr[i-1];//determine the elements in the golden cout<<div[i]<<"\n"; ratios if(j>0) //check if to continue or not dif=fabs(div[j-1]-div[j]); } i++; j++; }while(dif>=0.001); flushall(); getch(); return 0; } SAMPLE RUN: Program to print the golden ratios of Fibonacci Series 1 2 1.5 1.666667 1.6 1.625 1.615385 1.619048 1.617647 1.618182 DISCUSSION ANDCONCLUSION: This program uses various loops. One loop is used to create the elements in the Fibonacci Series, other one is used to create the elements in the golden ratio & the next one is used to determine how long the determining of the golde n ratio elements should go on.

Вам также может понравиться