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:
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!
@@coding::1@@
@@coding::2@@
Factorial using recursion is easier and less complex.
@@coding::4@@
#include<stdio.h>nint main(int a, char *b[]) n{nint x, y, fact = 1, i;nx = atoi(b[1]); //atoi function is to convert a character to integernfor(i = 1; i <= x; i++)n{nfact = fact * i;n}nprintf("%d", fact);nreturn 0;n}n