0% found this document useful (0 votes)
7 views2 pages

Factorial

Uploaded by

Karthik Nadar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Factorial

Uploaded by

Karthik Nadar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

5.

Factorial

C
#include <stdio.h>

int factorial(int n) {
// Complete the base case and recursive logic
if () {
return 1;
} else {
return n * factorial(/* recursive call */);
}
}

int main() {
int num = 5;
printf("Factorial: %d\n", factorial(num));
return 0;
}

Java
public class Main {
public static void main(String[] args) {
int num = 5;
System.out.println("Factorial: " + factorial(num));
}

static int factorial(int n) {


// Complete the base case and recursive logic
if (/* base case */) {
return 1;
} else {
return n * factorial(/* recursive call */);
}
}
}

Python
def factorial(n):
# Complete the base case and recursive logic
if # base case:
return 1
else:
return n * factorial(# recursive call)

num = 5
print("Factorial:", factorial(num))

You might also like