User Name Password Register
DaniWeb IT Discussion Community
All
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
May 7th, 2008
Views: 1,116
ITERATIVE AND RECURSIVE PROGRAMS.THESE PROGRAMS HAVE BEEN TESTED AND RUN VERY WELL.ENJOY
c Syntax | 1 stars
  1. # include<stdio.h>
  2. # include<conio.h>
  3. # include<stdlib.h>
  4.  
  5. void main()
  6. { int i,x,fib,a=0,b=1;
  7. textbackground(BROWN);
  8. textcolor(BLUE);
  9. clrscr();
  10. printf("\t\t THIS PROGRAM GENERATES THE FIBONACCI SEQUENCE\n\n\n\t");
  11. printf("ENTER THE FIBONACCI NUMBER THAT YOU WANT:\t");
  12. scanf("%d",&fib);
  13. if(fib==0)
  14. printf("\n0");
  15. else if(fib==1)
  16. printf("\n%d\t%d",a,b);
  17. else if(fib<0)
  18. printf("THE NUMBER IS INVALID");
  19. else if(fib>1)
  20. {
  21. printf("\n%d\t%d",a,b);
  22. for(i=2;i<=fib;i++)
  23. {
  24. x=a;
  25. a=b;
  26. b=x+b;
  27. printf("\t%d",b);
  28. }
  29. getch();
  30. }}
  31.  
  32. //recursive function
  33. // # include<stdio.h>
  34. // # include<conio.h>
  35.  
  36. // int fib(int num);
  37. // int main()
  38. // {
  39. // clrscr();
  40. // int num,loop;
  41. // printf("enter the fibonacci number");
  42. // scanf("%d",&num);
  43. // for(loop=0;loop<=num;loop++)
  44. // printf("%d",fib(loop));
  45. // getch();
  46. // return 0;
  47. // }
  48. // int fib(num)
  49. // {
  50. // if(num==0)
  51. // return 0;
  52. // else if(num==1)
  53. // return 1;
  54. // else if(num>1)
  55. // return (fib(num-1)+fib(num-2)
  56. // return 0;
  57. // }
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 5:56 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC