Factorial in V

Published on 16 December 2024 (Updated: 16 December 2024)

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

Current Solution

module main

import os
import strconv

fn factorial(n u64) u64 {
	return match true {
		n <= 1 { 1 }
		else { n * factorial(n-1) }
	}
}

fn usage() {
	println("Usage: please input a non-negative integer")
	exit(1)
}

fn main() {
	if os.args.len != 2 {
		usage()
	}

	n := strconv.atoi(os.args[1]) or {
		usage()
		exit(1)
	}
	if n < 0 {
		usage()
	}
	println(factorial(u64(n)))
}

Factorial in V 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.