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 :: how prevent user remove file linux 
Csharp :: linq contains 
Csharp :: c# httpclient post no content 
Csharp :: c# xml check if attribute exists 
Csharp :: check if element in hashset c# 
Csharp :: c# property attribute 
Csharp :: datagridview column index 
Csharp :: c# async and await example 
Csharp :: oncollisionenter2d 
Csharp :: selenum wait for element c# 
Csharp :: dotnet core encryption and decryption 
Csharp :: unity save scene at runtime 
Csharp :: list cast< c# 
Csharp :: elasticsearch nested aggregation in c# 
Csharp :: c# get name of type 
Csharp :: instantiate object inside of object Unity 
Csharp :: c# reverse a string for loop 
Csharp :: user input to array object c# 
Csharp :: linq where condition c# 
Csharp :: entity 
Csharp :: calculate textbox value c# 
Csharp :: unity SceneTemplatePipeline 
Csharp :: unity android keycodes 
Csharp :: read only variable in c# 
Csharp :: C# HttpUtility not found / missing C# 
Csharp :: how to hide tree level button when no record found for devexpress child grid view in Winform c# 
Csharp :: entity framework linq join 2 tables c# 
Csharp :: Toggle value change 
Csharp :: Running C# Example 
Csharp :: C# Search in JSON without deserialization 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =