Skip to content

Commit d419e82

Browse files
committed
Day 9
1 parent d343731 commit d419e82

File tree

5 files changed

+72
-1
lines changed

5 files changed

+72
-1
lines changed

Day9-Recursion/C++/main.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
int factorial(int n) {
6+
return (n > 1) ? n * factorial(n - 1) : 1;
7+
}
8+
9+
int main() {
10+
int n;
11+
cin >> n;
12+
cout << factorial(n);
13+
return 0;
14+
}

Day9-Recursion/C/main.c

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <stdio.h>
2+
3+
int factorial(int n){
4+
5+
return (n == 1) ? 1 : n * factorial(n - 1);
6+
7+
};
8+
9+
int main() {
10+
int n;
11+
scanf("%d", &n);
12+
printf("%d", factorial(n));
13+
return 0;
14+
}

Day9-Recursion/Java/main.java

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
public class Solution {
2+
3+
public static int factorial(int n){
4+
return (n > 1) ? n * factorial(n - 1) : 1;
5+
}
6+
7+
public static void main(String[] args) {
8+
Scanner scan = new Scanner(System.in);
9+
int n = scan.nextInt();
10+
scan.close();
11+
System.out.println(factorial(n));
12+
}
13+
}

Day9-Recursion/README.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## Objective
2+
Today, we're learning and practicing an algorithmic concept called Recursion.
3+
4+
## Task
5+
Write a factorial function that takes a positive integer, N as a parameter and prints the result of N! (N factorial).
6+
7+
## Input Format
8+
```
9+
A single integer, N (the argument to pass to factorial).
10+
```
11+
12+
## Constraints
13+
```
14+
Your submission must contain a recursive function named factorial.
15+
```
16+
17+
## Output Format
18+
```
19+
Print a single integer denoting .
20+
```
21+
22+
## Sample Input
23+
```
24+
3
25+
```
26+
27+
## Sample Output
28+
```
29+
6
30+
```

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The repository covers all the basic topics of programming languages. Try a new c
1515
- [Day 6 - Review](https://github.com/geekayush/30daysofcode/tree/master/Day6-Review)
1616
- [Day 7 - Arrays](https://github.com/geekayush/30daysofcode/tree/master/Day7-Arrays)
1717
- [Day 8 - Dictionaries&Maps](https://github.com/geekayush/30daysofcode/tree/master/Day8-Dictionaries&Maps)
18-
18+
- [Day 9 - Recursion](https://github.com/geekayush/30daysofcode/tree/master/Day9-Recursion)
1919

2020
##### How to contribute?
2121

0 commit comments

Comments
 (0)