// C++ program to find factorial of given number
#include <iostream>
using namespace std;
// function to find factorial of given number
unsigned int factorial(unsigned int n)
{
if (n == 0)
return 1;
return n * factorial(n - 1);
}
// Driver code
int main()
{
int num = 5;
cout << "Factorial of "
<< num << " is " << factorial(num) << endl;
return 0;
}
// This code is contributed by Shivi_Aggarwal
# Python 3 program to find
# factorial of given number
# Function to find factorial of given number
def factorial(n):
if n == 0:
return 1
return n * factorial(n-1)
# Driver Code
num = 5;
print("Factorial of", num, "is",
factorial(num))
# This code is contributed by Smitha Dinesh Semwal
// Java program to find factorial of given number
class Test {
// method to find factorial of given number
static int factorial(int n)
{
if (n == 0)
return 1;
return n * factorial(n - 1);
}
// Driver method
public static void main(String[] args)
{
int num = 5;
System.out.println("Factorial of " + num
+ " is " + factorial(5));
}
}
// C# program to find factorial
// of given number
using System;
class Test {
// method to find factorial
// of given number
static int factorial(int n)
{
if (n == 0)
return 1;
return n * factorial(n - 1);
}
// Driver method
public static void Main()
{
int num = 5;
Console.WriteLine("Factorial of "
+ num + " is " + factorial(5));
}
}
// This code is contributed by vt_m
<script>
// Javascript to find factorial
// of given number
// function to find factorial
// of given number
function factorial(n) {
if (n == 0) return 1;
return n * factorial(n - 1);
}
// Driver Code
let num = 5;
document.write("Factorial of " + num + " is " + factorial(num));
// This code is contributed by Saurabh Jaiswal
</script>