Horje
factorial Code Example
calculate factorial
int factorial(int n) {
	int res = 1, i; 
    for (i = 2; i <= n; i++) 
        res *= i; 
    return res; 
}
factorial
function factorial (n){
  j = 1;
  for(i=1;i<=n;i++){
    j = j*i;
  }
  return j;
}
factorial
unsigned long long factorial(unsigned long long num){

    if(num<=0)
        return 1;

    return num * factorial(num-1);
}
factorial
// FACTORIAL 
// 5! = 5 * 4 *3 * 2 *1 = 120 

const number = 5;
let fact =1 ;

for(let i=number;i>=1;i--)
{
  console.log(i)
  fact = fact * i;
}
console.log("FACTORIAL is :: ",fact);
factorial
public static void  factorial(int num){

    if(num<=0)
        return 1;

    return num * factorial(num-1);
}
factorial
//Java program to find factorial of a numberimport java.util.Scanner;public class factorial{		public static void main(String[] args)	{		//scanner class declaration		Scanner sc = new Scanner(System.in);		//input from user		System.out.print("Enter a number : ");						int number = sc.nextInt();		if(number >= 0)		{			//declare a variable to store factorial			int fac = 1;			for(int i = number ; i >= 1 ; i--)			fac = fac * i;			//display the result			System.out.println("Factorial of "+number+" is "+fac);			//closing scanner class(not compulsory, but good practice)		}		else			System.out.println("Value is not defined, please re-enter the value");		sc.close();														}}




Cpp

Related
interface in c++ Code Example interface in c++ Code Example
descending order c++ Code Example descending order c++ Code Example
pop off end of string c++ Code Example pop off end of string c++ Code Example
static_cast c++ Code Example static_cast c++ Code Example
ifstream Code Example ifstream Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
13