Skip to content

Commit

Permalink
Added factorial.cpp, fibonacci.cpp; Updated README.md (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
Razdeep committed Jan 7, 2019
1 parent c425ca9 commit b946809
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
22 changes: 22 additions & 0 deletions day13/C++/factorial.cpp
@@ -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;
}
30 changes: 30 additions & 0 deletions day13/C++/fibonacci.cpp
@@ -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;
}
64 changes: 64 additions & 0 deletions day13/README.md
Expand Up @@ -86,6 +86,34 @@ public class Factorial {
}
```

## C++ Implementation

#### [Solution](./C++/factorial.cpp)

```cpp
/**
* @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;
}
```
***
***
Expand Down Expand Up @@ -166,4 +194,40 @@ public class Fibonacci {
}
}
}
```
## C++ Implementation

#### [Solution](./C++/fibonacci.cpp)

```cpp
/**
* @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;
}
```

0 comments on commit b946809

Please sign in to comment.