Write a Program for factorial of a number in c language , java language and python language by technic dude
program of factorial Number in C
#include <stdio.h
unsigned int factorial(unsigned int n)
{
if (n == 0)
return 1;
return n * factorial(n - 1);
}
int main()
{
int num = 4;
printf("Factorial of %d is %d", num, factorial(num));
return 0;
}
Output
Factorial of 4 is 24
Write a program of factorial Number in JAVA
class Fact {
// 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 = 4;
System.out.println("Factorial of " + num
+ " is " + factorial(4));
}
}
Output
Factorial of 4 is 24
Find factorial Number in PYTHON Language
def factorial(n):
if n == 0:
return 1
return n * factorial(n-1)
num = 5;
print("Factorial of", num, "is",
factorial(num))
Output
Factorial of 4 is 24
0 Comments