C Program to find out a given number is power of 2 or not

Spread the love
#include<stdio.h>
main()
{
int n,result=1;
printf(“Enter any no :”);
scanf(“%d”,&n);
if(n<=0)
{
printf(“No Power to Negative Numbern”);
return;
}
while(result < n)
{
result = result * 2;
}

if(result == n)
{
printf(“%d is Power of 2..n”,n);
}
else
{
printf(“%d is not power of 2n”,n);
}

}
/****************** OUTPUT **************/


Venkatesh Macha

Hi Guys, I am Venkatesh Macha. I am a programmer and an Open Source enthusiast, Presently working as a Software Engineer. Apart from that, I love to explore new technologies and things.

You may also like...

Leave a Reply