Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* program to print a fibonacci series upto a certain number */
- #include<stdio.h>
- #include<conio.h>
- void main()
- {
- int n,first=0,second=1,third;
- clrscr();
- printf("Enter n: ");
- scanf("%d",&n);
- if(n<0)
- printf("Series does not exist.");
- else if(n==0)
- printf("%d",first);
- else
- {
- printf("%d %d",first,second);
- third=first+second;
- while(third<=n)
- {
- printf(" %d",third);
- first=second;
- second=third;
- third=first+second;
- }
- }
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment