C Program For Fibonacci Series Program to generate the following series up to nth term : 1/f1, 8/f2, 2/f3, 10/f4, 3/f5, 12/f6, 4/f7, 14/f8, 5/f9, 16/f10, . . . , 10/f19, 26/f20, . . . Where, n is a positive even integer,and f1, f2, f3, . . . are Fibonacci numbers. Source Code: #include<stdio.h> #include<conio.h> int fibo(int); int main() { int i,n; float j,f; int n1=1,n2=6; clrscr(); printf("enter the range of the series:"); scanf("%d",&n); if(n%2==0) { printf("\n the series is:\n\n"); for(i=1;i<=n;i++) { if(i%2!=0) { printf("%d/%d",n1++,fibo(i)); } else printf("%d/%d",n2+=2,fibo(i)); } n1=1,n2=8; printf("\n\n=>"); for(i=1;i<=n;i++) { f=fibo(i); if(i%2!=0) { j=n1/f; n1++; printf("%g ",j); } else { j=n2/f; n2=n2+2; printf("%g ",j); } } } else printf("the range is:"); getch(); return 0; } int fibo(int n) { if(n==1||n==2) return 1; else return(fibo(n-1)+fibo(n-2)); } output enter the range of the series:6 the series is: 1/1 8/1 2/2 10/3 3/5 12/8 =>1 8 1 3.33333 0.6 1.5
Tags:
C Program
1 comments
good work
ReplyDeleteprograms on finger tips now