Search This Blog

Thursday, June 2, 2016

Check for Power of Two for a given number

 #include <stdio.h>  
 main()  
 {  
     int num = 0;  
     printf("Enter number:");  
     scanf("%d",&num);  
     if ( !(num & (num-1)) )  
     {  
         printf("Power of two\n");  
     } else {  
         printf("Not a power of two\n");  
     }  
 }  

No comments:

Post a Comment