Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

factorial of any number

        public static void Factorial(int n)
        {
            var number = new int[999999];
            number[0] = 1;
            int numLength = 1;
            for (int times = 2; times <= n; times++)
                numLength = Multiply(times, number,numLength);

            for (int i = numLength - 1; i >= 0; i--)
                Console.Write(number[i]);
        }

        
        static int Multiply(int times, int[] number,int numLength)
        {
            int carry = 0; 
            for (int i = 0; i < numLength; i++)
            {
                int product = number[i] * times + carry;
                number[i] = product % 10;
                carry = product / 10;
            }

            while (carry != 0)
            {
                number[numLength] = carry % 10;
                carry /= 10;
                numLength++;
            }
            return numLength;
        }
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

PREVIOUS NEXT
Code Example
Csharp :: the name scripts does not exist in the current context mvc 5 
Csharp :: c# decimal to fixed 2 
Csharp :: c# datagridview center cell text 
Csharp :: modal barrier in flutter 
Csharp :: How to get selected item from Dropdown in GridView 
Csharp :: mysql restore backup from multiple files 
Csharp :: C# Change color 
Csharp :: c# check that value is not null or 0 
Csharp :: rigidbody.velocity.magnitude 
Csharp :: unity find deactivated gameobject 
Csharp :: Generic Stack 
Csharp :: c# switch when 
Csharp :: fill dictionary c# 
Csharp :: narcissistic 
Csharp :: install active directory windows server 2019 powershell 
Csharp :: dbset properties 
Csharp :: c# extension 
Csharp :: loop in c# 
Csharp :: list contains type c# 
Csharp :: dateTime first/last 
Csharp :: unity move camera to player fluent 
Csharp :: IOException: Failed to prepare target build directory. Is a built game instance running? UnityEditor.WindowsStandalone.WindowsDesktopStandalonePostProcessor.DeleteDestination (UnityEditor.Modules.BuildPostProcessArgs args) 
Csharp :: c#, get a embedded resx file 
Csharp :: How to cache database tables to prevent many database queries in Asp.net C# mvc 
Csharp :: what is napalm made of 
Csharp :: camera is rendering black screen unity 
Csharp :: c# sequential struct char array fixed size 
Csharp :: [Package Manager Window] Error while fetching labels: User is not logged in or user status invalid. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&) 
Csharp :: c# aabb box rotate 
Csharp :: back color for DateTimePicker control 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =