Added function to comput factorial of number
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
--luaClasses/Algorithms.lua
|
||||
--Matthew Ellison
|
||||
-- Created: 02-04-19
|
||||
--Modified: 03-28-19
|
||||
--Modified: 06-01-21
|
||||
--This is a file of algorithms that I have found it useful to keep around at all times
|
||||
--[[
|
||||
Copyright (C) 2019 Matthew Ellison
|
||||
Copyright (C) 2021 Matthew Ellison
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
@@ -353,3 +353,11 @@ function gcd(num1, num2)
|
||||
end
|
||||
return num1 | num2;
|
||||
end
|
||||
|
||||
function factorial(num)
|
||||
local fact = 1;
|
||||
for cnt = 1, num do
|
||||
fact = fact * cnt;
|
||||
end
|
||||
return fact;
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user