Test output value to check if it is INTEGER

Asked

Viewed 1,032 times

1

I set the function below to check if the output value is integer or real.

 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

If it is real, you should not display anything on the screen.

If integer, it should display a message "é potencia de 2"

How to test if LOGARITHM is INTEGER?

  • would be that if it is integer then it displays on the screen the message otherwise does not display because the number is not power of two.

  • so the topic is named Test output value to check if it is INTEGER if the test = int then prints message otherwise it does nothing!

  • As far as I know, it is not possible to do MOD(%) in real numbers, if this is possible your algorithm already does this, because if it is real it would return a real value as a result of MOD and would not pass in the condition of SE.

1 answer

1

Use the function int to truncate the value. If the original value is equal to the truncated, it is integer.

SE logaritmo = int(logatimo) ENTAO

Browser other questions tagged

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