Link copied to clipboard. Share away!

Dissmis

Published on 09 Mar 2020

Factorial program in C (with and without using command lines), C++ and other languages is discussed here. There are 4 methods to find the factorial of a number. They are:

- Using tgamma function
- Using for loop
- Using recursion
- Using functions

The solution for all these methods is explained below.

**Explanation: **Factorial of a non-negative integer n, denoted by n! It is the product of all positive integers less than or equal to n. For example,

tgamma function is used to calculate factorial of a number. While using this function, you need to include the math.h header file.This function works only till 20!

C

C++

Output

Input-
Enter the number:5
Output-
Factorial of the number 5 is 120

C

C++

Java

Python 3

Output

Input-
Enter the number:5
Output-
Factorial of the number 5 is 120

Factorial using recursion is easier and less complex.

C

C++

Java

Python 3

Output

Input-
Enter the number:5
Output-
Factorial of the number 5 is 120

```
#include<stdio.h>
int main(int a, char *b[])
{
int x, y, fact = 1, i;
x = atoi(b[1]); //atoi function is to convert a character to integer
for(i = 1; i <= x; i++)
{
fact = fact * i;
}
printf("%d", fact);
return 0;
}
```

If you have any feedback about this
article and want to improve this, please write to **enquiry@faceprep.in**

×