Factorial in Powershell

Published on 20 May 2025 (Updated: 20 May 2025)

Welcome to the Factorial in Powershell page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

function Show-Usage() {
    Write-Host "Usage: please input a non-negative integer"
    Exit 1
}

function Get-Factorial([int]$Value) {
    $Product = 1
    if ($Value -gt 0) {
        1..$Value | ForEach-Object { $Product *= $_ }
    }

    $Product
}

if ($args.Length -lt 1) {
    Show-Usage
}

try {
    $Value = [int]::Parse($args[0])
} catch {
    Show-Usage
}

if ($Value -lt 0) {
    Show-Usage
}

Write-Host (Get-Factorial $Value)

Factorial in Powershell was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.