factorial
unsigned long long factorial(unsigned long long num){
if(num<=0)
return 1;
return num * factorial(num-1);
}
factorial
unsigned long long factorial(unsigned long long num){
if(num<=0)
return 1;
return num * factorial(num-1);
}
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));
}
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
//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(); }}
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();
}
factorial
public static void factorial(int num){
if(num<=0)
return 1;
return num * factorial(num-1);
}
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
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us