Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

program to calculate factorial of a number

#include<stdio.h>  
int main()    
{    
 int i,fact=1,number;    
 printf("Enter a number: ");    
  scanf("%d",&number);    
    for(i=1;i<=number;i++){    
      fact=fact*i;    
  }    
  printf("Factorial of %d is: %d",number,fact);    
return 0;  
}   
Comment

Program for factorial of a number

// C++ program to find factorial of given number
#include <iostream>
using namespace std;
 
// function to find factorial of given number
unsigned int factorial(unsigned int n)
{
    if (n == 0)
        return 1;
    return n * factorial(n - 1);
}
 
// Driver code
int main()
{
    int num = 5;
    cout << "Factorial of "
         << num << " is " << factorial(num) << endl;
    return 0;
}
 
// This code is contributed by Shivi_Aggarwal
Comment

find factorial of a number

# Factorial of a number using recursion

def recur_factorial(n):
   if n == 1:
       return n
   else:
       return n*recur_factorial(n-1)

num = 7

# check if the number is negative
if num < 0:
   print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
   print("The factorial of 0 is 1")
else:
   print("The factorial of", num, "is", recur_factorial(num))
Comment

find a factorial of a number

<?php
              
      $num = 3;
      $factorial = 1;
      if($num != 0) {
        for($i = $num; $i>=1; $i--) {
          $factorial = $factorial * $i;
        }
      }
      else {
        $factorial = 1;
      }
      echo "Factorial of $num is $factorial";

    ?>
Comment

Program for factorial of a number

// Java program to find factorial of given number
class Test {
    // method to find factorial of given number
    static int factorial(int n)
    {
        if (n == 0)
            return 1;
 
        return n * factorial(n - 1);
    }
 
    // Driver method
    public static void main(String[] args)
    {
        int num = 5;
        System.out.println("Factorial of " + num
                           + " is " + factorial(5));
    }
}
Comment

Program for factorial of a number

// Java program to find factorial of given number
class Test {
    // method to find factorial of given number
    static int factorial(int n)
    {
        if (n == 0)
            return 1;
 
        return n * factorial(n - 1);
    }
 
    // Driver method
    public static void main(String[] args)
    {
        int num = 5;
        System.out.println("Factorial of " + num
                           + " is " + factorial(5));
    }
}
Comment

Program for factorial of a number

// C program to find factorial of given number
#include <stdio.h>
 
// function to find factorial of given number
unsigned int factorial(unsigned int n)
{
    if (n == 0)
        return 1;
    return n * factorial(n - 1);
}
 
int main()
{
    int num = 5;
    printf("Factorial of %d is %d", num, factorial(num));
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript if null use other value 
Javascript :: pwa tabs chrome extension 
Javascript :: enable cors on eleventy 
Javascript :: complete date 
Javascript :: tips and tricks for javascript 
Javascript :: convert python to js online 
Javascript :: Extract JSON from http page request 
Javascript :: liquid - array item accessing 
Javascript :: javascript in array 
Javascript :: javascript only works in codepen 
Javascript :: rails json exclude nested attribute 
Javascript :: MAT_DIALOG_SCROLL_STRATEGY 
Javascript :: button prssed value show in text javascript 
Javascript :: open menu 
Javascript :: package.json view html report 
Javascript :: Set initial state on react-native-router-flex 
Javascript :: 8.1.4. Array Length or .length 
Javascript :: discord.js ban 
Javascript :: javascript look hack 
Javascript :: conditionals monads javascript 
Javascript :: Spotify analytics intergration 
Javascript :: javascript get local timezone 
Javascript :: arrow function no need for curly braces bc just one action 
Javascript :: global keyboard shortcuts react 
Javascript :: ex: Javascript 
Javascript :: equals sign vue js 
Javascript :: javascript loop all depths recursive object 
Javascript :: idenmnify 
Javascript :: Comparison Primitive operations Methods 
Javascript :: javascript array same class elements 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =