AbdulFathaah

fibonacci upto n

Sep 25th, 2023
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. /* program to print a fibonacci series upto a certain number */
  2.  
  3. #include<stdio.h>
  4. #include<conio.h>
  5. void main()
  6. {
  7. int n,first=0,second=1,third;
  8. clrscr();
  9. printf("Enter n: ");
  10. scanf("%d",&n);
  11. if(n<0)
  12. printf("Series does not exist.");
  13. else if(n==0)
  14. printf("%d",first);
  15. else
  16. {
  17. printf("%d %d",first,second);
  18. third=first+second;
  19. while(third<=n)
  20. {
  21. printf(" %d",third);
  22. first=second;
  23. second=third;
  24. third=first+second;
  25. }
  26. }
  27. getch();
  28. }
Advertisement
Add Comment
Please, Sign In to add comment