Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added factorial.cpp, fibonacci.cpp; Updated README.md (#138)
- Loading branch information
Showing
3 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* @author: Rajdeep Roy Chowdhury<rrajdeeproychowdhury@gmail.com> | ||
* @github: https://github.com/razdeep | ||
* @date: 07/01/2019 | ||
*/ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
long long factorial(long long n) | ||
{ | ||
if (n <= 1) | ||
return 1; | ||
return n*factorial(n-1); | ||
} | ||
int main() | ||
{ | ||
long long n; | ||
cout<<"Enter a number "; | ||
cin>>n; | ||
cout<<"The factorial of "<<n<<" is "<<factorial(n)<<endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* @author: Rajdeep Roy Chowdhury<rrajdeeproychowdhury@gmail.com> | ||
* @github: https://github.com/razdeep | ||
* @date: 07/01/2019 | ||
*/ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
long long fibonacci(long long n) | ||
{ | ||
if (n <= 2) | ||
return 1; | ||
return fibonacci(n-1)+fibonacci(n-2); | ||
} | ||
int main() | ||
{ | ||
long long n; | ||
cout<<"Enter a number "; | ||
cin>>n; | ||
string pos; | ||
if(n%10 == 1) | ||
pos="-st"; | ||
else if(n%10 == 2) | ||
pos="-nd"; | ||
else | ||
pos="-th"; | ||
|
||
cout<<"The "<<n<<pos<<" number of the fibonacci series is "<<fibonacci(n)<<endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters