Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Disclosure: My content contains affiliate links.

43,181 questions

56,073 answers

573 users

How to compute the factorial of a number greater than 20 in VB.NET

1 Answer

0 votes
Imports System
Imports System.Numerics

' 
'   This program computes the factorial of numbers greater than 20.
'   VB.NET provides the BigInteger type, which supports arbitrary‑precision
'   arithmetic and is ideal for very large factorials.
'

Module BigFactorial

    '
    '   Compute factorial using BigInteger.
    '   The algorithm multiplies numbers from 2 to n.
    '   BigInteger handles overflow internally and grows as needed.
    '
    Function FactorialBig(n As Integer) As BigInteger
        Dim result As BigInteger = BigInteger.One

        For i As Integer = 2 To n
            result *= i
        Next

        Return result
    End Function

    '
    '   Main entry point: read input, compute factorial, print result.
    '
    Sub Main()
        Console.Write("Enter a number greater than 20: ")
        Dim n As Integer = Integer.Parse(Console.ReadLine())

        Dim result As BigInteger = FactorialBig(n)

        Console.WriteLine()
        Console.WriteLine("Factorial of " & n & " is:")
        Console.WriteLine()
        Console.WriteLine(result)
    End Sub

End Module


'
' run:
'
' Enter a number greater than 20: 25
' 
' Factorial of 25 is:
' 
' 15511210043330985984000000
'

 



answered 4 days ago by avibootz

Related questions

...