Using LOG in VISUALG Functions

Asked

Viewed 1,158 times

2

When using visualG LOG there is a problem, I need to divide a value typed by the user, by log 2 in base 10. Only he doesn’t make it he’s wrong.

funcao menu_8():inteiro
var
logaritmo :real
inicio
para contador de 0 ate 12 faca
      logaritmo <- ((log(i[contador])) / (log(2)))
      se ((logaritmo % 2 = 0) OU (logaritmo % 2 = 1)) entao
         escreva(" é Potencia de 2: ", i[contador])
      fimse
fimpara
escreval(" ")
fimfuncao

after the IF function is executed and the result of the division is an INTEGER value, without comma, it prints the message, otherwise, it loops the repetition with another value of the vector, until it finds a number that is power 2, if none is, then it goes out and does not print anything.

what’s the easiest way to solve this?

1 answer

1

The problem is in the comparison, exactly in the SE, you should check if the result is integer otherwise, if you do not have a function relative to "module" (MOD) that usually captures only the fractional part of a Real number, not all languages have, if not, do with the function that picks up the whole part, so:

If INT(Result) - Result = 0 , then the operation does not present rest, ie, it is an integer.

For example:

Se   INT(123) - 123 = 0  'Então  123  É um número inteiro

Se   INT(45,678) - 45,678 = 0,678  'Então  45,678 NÃO É um número inteiro
  • Hi @Agenaro, saw my reply?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.