# Answer to Question #5193 in C++ for aswinrdev

Question #5193

A PROGRAM TO GENERATE FIBANOCCI UPTO A GIVEN NO 112358

Expert's answer

#include <iostream.h>

int fib(int n)

{

if((1 == n) || (2 == n)) return 1;

else return fib(n-1) + fib(n-2);

}

int main(){

int i, n;

cout<<"enter n:";

cin>>n;

for(i=1; i<=n; i++) cout << fib(i) << endl;

return 0;

}

int fib(int n)

{

if((1 == n) || (2 == n)) return 1;

else return fib(n-1) + fib(n-2);

}

int main(){

int i, n;

cout<<"enter n:";

cin>>n;

for(i=1; i<=n; i++) cout << fib(i) << endl;

return 0;

}

## Comments

## Leave a comment