File tree 5 files changed +72
-1
lines changed
5 files changed +72
-1
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ ```
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ The repository covers all the basic topics of programming languages. Try a new c
15
15
- [ Day 6 - Review] ( https://github.com/geekayush/30daysofcode/tree/master/Day6-Review )
16
16
- [ Day 7 - Arrays] ( https://github.com/geekayush/30daysofcode/tree/master/Day7-Arrays )
17
17
- [ 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 )
19
19
20
20
##### How to contribute?
21
21
You can’t perform that action at this time.
0 commit comments