local matrix = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9},
}
local function extract_even_odd_form(matrix)
local even_matrix, odd_matrix = {},{}
for _, outer in ipairs(matrix) do
for _, value in ipairs(outer) do
if value % 2 == 0 then
table.insert(even_matrix, value)
end
if value % 2 ~= 0 then
table.insert(odd_matrix, value)
end
end
end
return even_matrix, odd_matrix
end
local function read_matrix(matrix)
for _, v in ipairs(matrix) do
io.write(v.."\t")
end
io.write("\n")
end
local even, odd = extract_even_odd_form(matrix)
print("Qunatidade de números contados: " .. tostring(#even + #odd))
print("Números pares:")
read_matrix(even)
print("Números ímpares:")
read_matrix(odd)
To embed this project on your website, copy the following code and paste it into your website's HTML: