Home › Forums › C Programming › program for fibonacci series
- This topic has 2 replies, 3 voices, and was last updated 16 years, 3 months ago by berhane.
Viewing 2 reply threads
- AuthorPosts
- September 11, 2008 at 2:59 am #2140bajeanParticipant
frienz plz help me in making a progarm for fibonacci series by recursion method……
this is the pattern for fibonaci series:
0 1 1 2 3 5 8 13 21 34 55……and so on…remember u have to code by recursion method…..
- September 11, 2008 at 12:06 pm #3456HumayanParticipant
try:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162/****************************************************************<br />* File Name : c:programshelpfibonacci1.cpp<br />* Date : September,11,2008<br />* Comments : new project<br />* Compiler/Assembler :<br />* Program Shell Generated At: 3:40:46 p.m.<br />=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/<br /><br />#include < stdio.h ><br />//#include < string.h ><br />//#include < conio.h ><br />//#include < math.h ><br />//#include < iomanip ><br />//#include < ctype.h ><br /><br /><br />//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ FUNCTION PROTOTYPES @@@@@@@@@@@@@@@@@@@@@@@@@@<br />void fibonacci ( int firstTerm , int secondTerm , int numberOfTerms );<br />//##################################################################################<br /><br />//main function ******************************<br />int main ( )<br />{<br />int numberOfTerms;<br />printf ( "enter the number of terms: " );<br />scanf ( "%i" , & numberOfTerms );<br />fibonacci ( 0 , 1 , numberOfTerms );<br />printf ( "n" );<br />return 0 ;<br />}<br /><br />/******************************* FUNCTION DEFINITION ******************************<br />Name : fibonacci<br />Parameters :<br />firstTerm a(n) int ,<br />secondTerm a(n) int ,<br />numberOfTerms a(n) int<br /><br />Returns: Void type<br />Comments:<br /><br />++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/<br />void fibonacci ( int firstTerm , int secondTerm , int numberOfTerms )<br />{<br />if ( numberOfTerms == 0 )<br />{<br />return;<br />}<br />else<br />{<br />if ( firstTerm == 0 )<br />{<br />printf ( "0 1 " );<br />numberOfTerms -= 2;<br />}<br />printf ( "%i" , firstTerm + secondTerm );<br />printf ( " " );<br />fibonacci ( secondTerm , firstTerm + secondTerm , numberOfTerms - 1 );<br />}<br />return;<br />}<br /> - September 13, 2008 at 11:47 pm #3457berhaneParticipant1234567891011121314151617181920212223#include<stdio.h><br />void printfab(int,int,int);<br />void main()<br />{<br />int i=0,j=1,n;<br />printf("nEnter last limit ");<br />scanf("%d",&n);<br />printf("%d %d ",i,j);<br />printfab(i,j,n)<br />}<br />void printfab(int i,int j,int d)<br />{<br /><br />int temp;<br />while(temp<d)<br />{ <br />temp=i+j;<br />j=temp;<br />i=j;<br />printf('n %d",temp);<br />printfab(i,j,d);<br />} <br />
- AuthorPosts
Viewing 2 reply threads
- The forum ‘C Programming’ is closed to new topics and replies.