# Program to Find the factorial of a number

### Problem statement:- Program to Find the factorial of a number.

#### Sample Input/Output:-

Sample Input First: 5                      Sample Output First: 120

Sample Input Second: 7                 Sample Output Second5040

#### Explanation:-

For output 1st: 5*4*3*2*1=120

For output 2nd: 7*6*5*4*3*2*1=5040

Data requirement:-

Input Data:- num

Output Data:-fact

Program in C

Here is the source code of the C Program to Find the factorial of a number.

Code:

#include<stdio.h>
int main()
{
int num,i;
printf("Enter a number:");
scanf("%d",&num);
int fact=1;
for(i=1;i<=num;i++)
fact=fact*i;
printf("The factorial is %d",fact);
}

Input/Output:
Enter a number:
5
The factorial is 120

Program in C++

Here is the source code of the C++ Program to Find the factorial of a number.

Code:

#include<iostream>
using namespace std;
int main()
{
int num;
cout<<"Enter a number:";
cin>>num;
int fact=1;
for(int i=1;i<=num;i++)
fact=fact*i;
cout<<"The factorial is "<<fact;
}

Input/Output:
Enter a number:6
The factorial is 720

Program in Java

Here is the source code of the Java Program to Find the factorial of a number.

Code:

import java.util.Scanner;
public class FactorialOfNumber {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int num;
System.out.println("Enter a number:");
num=cs.nextInt();
int fact=1;
for(int i=1;i<=num;i++)
fact=fact*i;
System.out.println("The factorial is "+fact);
cs.close();
}
}

Input/Output:
Enter a number:
7
The factorial is 5040

Program in Python

Here is the source code of the Python Program to Find the factorial of a number.

Code:

num=int(input("Enter a number:"))
fact=1
for i in range(1,num+1):
fact=fact*i
print("The Factorial is",fact)

Input/Output:
Enter a number:10
The Factorial is 3628800