Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void Fibonacci(int limit);
- int main(void){
- int limit;
- printf("Enter a limit: \n");
- while(scanf("%d", &limit)==1 && limit!='q'){
- if (limit<0)
- printf("Try again.\n");
- Fibonacci(limit);
- printf("Enter a limit (q to quit): \n");
- }
- }
- void Fibonacci(int limit){
- int count=0, oldnum1=1, oldnum2=1, newnum;
- while (count<limit){
- if(count==0){
- printf("%d\n", oldnum1 );
- count++;
- }
- else if (count==1){
- printf("%d\n", oldnum2);
- count++;
- }
- else{
- newnum=oldnum1+oldnum2;
- printf("%d\n", newnum);
- oldnum1=oldnum2;
- oldnum2=newnum;
- count++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement