1function BracketCombinations(num) {
2 return (1 / (num + 1)) * choose(2 * num, num);
3}
4
5function fact(num) {
6 let sum = 1;
7 for (let i = 1; i <= num; i++) {
8 sum *= i;
9 }
10 return sum;
11}
12
13function choose(num, k) {
14 return fact(num) / 2 * (fact(k) * 1 / fact(num - k));
15}
1unsigned long long factorial(unsigned long long num){
2
3 if(num<=0)
4 return 1;
5
6 return num * factorial(num-1);
7}
1// FACTORIAL
2// 5! = 5 * 4 *3 * 2 *1 = 120
3
4const number = 5;
5let fact =1 ;
6
7for(let i=number;i>=1;i--)
8{
9 console.log(i)
10 fact = fact * i;
11}
12console.log("FACTORIAL is :: ",fact);
1//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(); }}
1#include<stdio.h>
2#include<conio.h>
3void main()
4{
5 int fact, i, n;
6 fact = 1;
7 printf("Enter the number\t");
8 scanf("%d" , &n);
9 for(i = 1; i <= n; i++)
10 {
11 fact = fact*i;
12 }
13 printf("Factorial of %d is %d", n , fact);
14 getch();
15}
1public static void factorial(int num){
2
3 if(num<=0)
4 return 1;
5
6 return num * factorial(num-1);
7}
1// METHOD ONE
2const factorialNumber = num => {
3 let factorials = []
4 for(let i = 1; i <= num; i++) factorials.push(i)
5 return factorials.reduce((acc , curr) => acc * curr, 1)
6}
7
8// METHOD TWO
9const factorialNumber = num => {
10 let factorial = 1, i = 1
11 while(i <= num){ factorial *= i; i++ }
12 return factorial
13}
14// METHOD THREE
15function factorialNumber(num) {
16 if(num < 1) return 1
17 else return factorialNumber(num - 1) * num
18}