I made this code that makes an Array (At least I think it's doing) and then writes all the values in it. obs: Values are random. I need to find the lowest value in the array, but the logic I've always used gives me a predictable result.
Example: Let's say the invertalo range is given by x and y . (X = 0 and y = 2500). In the code, the value of the smallest variable is always giving the smallest value that can be assumed and y x + 2, that is, in my code the small variable is always resulting in a value of 2. If I set the smallest value of the range to 5, the value of the smaller variable will be 7. (x = 5, x + 2 = 7)
matriz={}
for l=1,20 do
matriz[l]={}
for c=1,40 do
matriz[l][c] = math.random(0,2500)
end
end
menor = matriz[1][1]--Inicia na menor posição possivel
for i=1,20 do
for j=1,40 do
print("O valor na Linha:"..i.." Coluna:"..j.." é "..matriz[i][j])
if matriz[i][j]<menor then-- essa parte deveria encontrar o meno valor
menor = matriz[i][j]
end--Final
end
end
print("O menor valor encontrado é:"..menor)
This is the code I made, how I'm starting, I do not understand where his error is.