•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 402,507 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,859 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
ITERATIVE AND RECURSIVE PROGRAMS.THESE PROGRAMS HAVE BEEN TESTED AND RUN VERY WELL.ENJOY
# include<stdio.h> # include<conio.h> # include<stdlib.h> void main() { int i,x,fib,a=0,b=1; textbackground(BROWN); textcolor(BLUE); clrscr(); printf("\t\t THIS PROGRAM GENERATES THE FIBONACCI SEQUENCE\n\n\n\t"); printf("ENTER THE FIBONACCI NUMBER THAT YOU WANT:\t"); scanf("%d",&fib); if(fib==0) printf("\n0"); else if(fib==1) printf("\n%d\t%d",a,b); else if(fib<0) printf("THE NUMBER IS INVALID"); else if(fib>1) { printf("\n%d\t%d",a,b); for(i=2;i<=fib;i++) { x=a; a=b; b=x+b; printf("\t%d",b); } getch(); }} //recursive function // # include<stdio.h> // # include<conio.h> // int fib(int num); // int main() // { // clrscr(); // int num,loop; // printf("enter the fibonacci number"); // scanf("%d",&num); // for(loop=0;loop<=num;loop++) // printf("%d",fib(loop)); // getch(); // return 0; // } // int fib(num) // { // if(num==0) // return 0; // else if(num==1) // return 1; // else if(num>1) // return (fib(num-1)+fib(num-2) // return 0; // }
Post Comment
•
•
•
•
DaniWeb Marketplace (Sponsored Links)