ashu said:
its very simple
see
any variable it is divided by 3,5,7 or 9 then it is not the power of 2
By definition, a number that is a power of 2 has no prime factors other
than 2, your observation is an incomplete obfuscation of this fact.
Also, just so you know, any number evenly divisible by 9 is also evenly
divisible by 3 so the last part of your assertion is superfluous.
i.e,
main()
{
if (n%3 && n%5 && n%7 && n%9 != 0 )
printf("n is a power of 2");
}
Your example has numerious errors, both programatic and logical.
First, let's cover the programatic errors:
1. main returns an int so "int main (void)" would be a correct
declaration here.
2. You never define "n", let alone initialize it.
3. You need to #include <stdio.h> to use printf and you should have a
newline at the end of your string to be portable.
4. You should return an integer value from main.
It is true that any number evenly divisible by 3, 5, 7, or 9 is not a
power of 2, but to say that any number that does is not evenly
divisible by these numbers is a power of 2 is a non sequitur, by your
criteria 1, 11, 13, and would each be a power of 2.
Robert Gamble