Answers for "factorial"

C++
1

factorial

unsigned long long factorial(unsigned long long num){

    if(num<=0)
        return 1;

    return num * factorial(num-1);
}
Posted by: Guest on December-28-2020
0

factorial

function BracketCombinations(num) { 
  return (1 / (num + 1)) * choose(2 * num, num);
}

function fact(num) {
  let sum = 1;
  for (let i = 1; i <= num; i++) {
    sum *= i;
  }
  return sum;
}

function choose(num, k) {
  return fact(num) / 2 * (fact(k) * 1 / fact(num - k));
}
Posted by: Guest on May-23-2021
0

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);
Posted by: Guest on July-27-2021
0

factorial

#include<stdio.h>
#include<conio.h>
void main()
{
   int fact, i, n;
   fact = 1;
   printf("Enter the number\t");
   scanf("%d" , &n);
   for(i = 1; i <= n; i++)
   {
       fact = fact*i;
   }
   printf("Factorial of %d is %d", n , fact);
   getch();
}
Posted by: Guest on May-01-2021
0

factorial

public static void  factorial(int num){

    if(num<=0)
        return 1;

    return num * factorial(num-1);
}
Posted by: Guest on July-30-2021
-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();														}}
Posted by: Guest on June-10-2021
0

Factorial

// METHOD ONE
const factorialNumber = num => {
    let factorials = []
    for(let i = 1; i <= num; i++) factorials.push(i)
    return factorials.reduce((acc , curr) => acc * curr, 1)
}

// METHOD TWO
const factorialNumber = num => {
    let factorial = 1, i = 1
    while(i <= num){ factorial *= i; i++ }
    return factorial
}
// METHOD THREE
function factorialNumber(num) {
    if(num < 1) return 1
    else return factorialNumber(num - 1) * num
}
Posted by: Guest on July-02-2020

Browse Popular Code Answers by Language