int num = Convert.ToInt32(Console.ReadLine());
for (int i = 2; i <=num; i*=2)
{
if (i==num)
{
Console.WriteLine("It is power of 2");
}
else if (i!=num)
{
Console.WriteLine("It isn't power of 2");
}
}
Hello, what I want to do is determine if a number is a power of 2 or not. As you have seen in the code and may recognized, the problem that comes up is, for example, if I input 16 it will output
It isn't power of 2
It isn't power of 2
It isn't power of 2
It is power of 2
Because by that, the first three values of i
are 2, 4 and 8, and the last one 16. All said, how i do to refer to the last value of i