# Recursion problem solution - 30 days of code HackerRank

Input Format
A single integer,  (the argument to pass to factorial).
Output Format
Print a single integer denoting .

### Problem solution in the c programming language.

#include <stdio.h>

int factorial(int n){

return (n == 1) ? 1 : n * factorial(n - 1);

};

int main() {
int n;
scanf("%d", &n);
printf("%d", factorial(n));
return 0;
}

### Problem solution in C++ programming language.

#include <iostream>

using namespace std;

int factorial(int n) {
return (n > 1) ? n * factorial(n - 1) : 1;
}

int main() {
int n;
cin >> n;
cout << factorial(n);
return 0;
}

### Problem solution in Java programming language.

public class Solution {

public static int factorial(int n){
return (n > 1) ? n * factorial(n - 1) : 1;
}

public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
scan.close();
System.out.println(factorial(n));
}
}

### Problem solution in the python programming language.

import math
import os
import random
import re
import sys

# Complete the factorial function below.
def factorial(n):

if n == 1:
return 1
else:
n = n * factorial(n-1)
return n

if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')

n = int(input())

result = factorial(n)

fptr.write(str(result) + '\n')

fptr.close()