「モジュール:数学」の版間の差分

提供:WikiWiki
ナビゲーションに移動 検索に移動
(コメントの追加)
編集の要約なし
1行目: 1行目:
local p = {}
local p = {}


function getLmc(num1, num2) --2数の最小公倍数を求める関数
function p.getLmc(num1, num2) --2数の最小公倍数を求める関数
if type(num1) == number and type(num2) == number then
if type(num1) == number and type(num2) == number then
if num1 == 0 or num2 == 0 then
if num1 == 0 or num2 == 0 then

2年8月15日 (W) 17:03時点における版

このモジュールについての説明文ページを モジュール:数学/doc に作成できます

local p = {}

function p.getLmc(num1, num2) --2数の最小公倍数を求める関数
	if type(num1) == number and type(num2) == number then
		if num1 == 0 or num2 == 0 then
			return 0
		end
		if num1 == num2 then
			return num1
		end
		a, b = 1
		while num1 ~= num2 do
			if a*num1 > b*num2 then
				b = b + 1
			else
				a = a + 1
			end
		end
		return num1
	else
		return "'''関数 getLmc: 引数には数値のみを入力してください。'''"
	end
end

return p