Skip to content
This repository has been archived by the owner on Oct 1, 2021. It is now read-only.

fibonacci.cpp #396

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions fibonacci.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include<iostream>
using namespace std;

int Fib(int n)
{
if (n == 0 || n == 1)
{
return n;
}
else {
return Fib(n-1) + Fib(n-2);
}
}

int main(){
int n,j=0;
cout << "Enter the total number of terms:";
cin >> n;

for(int i=1; i<=n; i++)
{
int r = Fib(j);
cout << r << " ";
j++;
}
}