Added function to comput factorial of number

This commit is contained in:
2021-06-01 16:39:01 -04:00
parent 0c1d5d1094
commit a9de121a88
2 changed files with 48 additions and 3 deletions

View File

@@ -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