How to tell if a number is integer

3

I need to develop an algorithm where it divides a number by 2 until it reaches the rest of the division, and I need to know if the rest of this division is an integer, what method can I apply to develop this problem?

where:

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

This algorithm will be applied, in the following, if the user type in the vector, a number that is power of 2, should display this value.

Where will I use Base Log 10 to divide the number entered by 2 log of 10, and if the result of dividing an integer, ai means that base is two, the number entered by the user, if otherwise it is not.

    
asked by anonymous 01.06.2016 / 20:17

1 answer

4

Rest of division is an integer, by definition. If it is not whole, it is not rest. Alias the whole description of the problem does not seem to make the least sense. I'll answer the title of the question.

Basically this is it:

x == int(x)

The second expression converts the number to an integer. If it stays the same, it means that it is integer, if it is different, it is because the number had a decimal part.

    
01.06.2016 / 21:01