# Compute Factorial of a Number

“** Compute Factorial of a Number**” is very popular programming exercise problem for beginners. Here, we are given a number, enter by user and our task is to compute factorial of a number.

Factorial of a N: N! = N*(N-1)*(N-2)*..*2*1.

**Example:**

N = 5INPUT:120OUTPUT:

**C++ Program to compute factorial of a number is as follows:**

#include<bits/stdc++.h> using namespace std; int main() { int num; //Scan the number cout<<"Enter the number:"; cin>>num; //Computing factorial int factorial = 1; for(int i = num ; i >= 1 ; i--) { factorial = factorial * i; } //Printing the factorial cout<<"Factorial of "<<num<<" is "<<factorial; }

Enter the number: 5 Factorial of 5 is 120OUTPUT:

**Related Posts:**

**Program to find GCD of two numbers.****Program to find LCM of two numbers.****Program to check whether entered number is odd or even.****Program to check whether entered number is prime number or not.****Program to check whether entered number is palindrome or not.****Program to check whether entered number is Armstrong Number or Not.****Program to convert binary number to octal number.****Program to convert binary number to decimal number.****Program to convert binary number to hexadecimal number.****Program to convert octal number to binary number.****Program to convert octal number to decimal number.****Program to convert octal number to hexadecimal number.****Program to convert decimal number to binary number.****Program to convert decimal number to octal number.****Program to convert decimal number to hexadecimal number.****Program to convert hexadecimal number to binary number.****Program to convert hexadecimal number to octal number.****Program to convert hexadecimal number to decimal number.****Program to check Leap Year.****Program to find sum of first ‘n’ natural numbers.**