Accelerate
00:00
Level Leaderboard
2
Accelerate
@KaiKoKenzooie
-- Function to calculate the factorial of a number
function factorial(n)
if n == 0 then
return 1
else
return n * factorial(n - 1)
end
end
-- Get user input
print("Enter a number:")
local input = io.read("*n") -- Read a number from the user
-- Calculate factorial
local result = factorial(input)
-- Print the result
print("The factorial of " .. input .. " is " .. result)
function factorial(n)
if n == 0 then
return 1
else
return n * factorial(n - 1)
end
end
-- Get user input
print("Enter a number:")
local input = io.read("*n") -- Read a number from the user
-- Calculate factorial
local result = factorial(input)
-- Print the result
print("The factorial of " .. input .. " is " .. result)
Restart
Full Screen
to Play/Pause the video.
to restart the level.