VB icon

Efficient_Power_Of_2

Email
Submitted on: 1/6/2015 12:21:00 AM
By: Balram Reddy Kakani (from psc cd)  
Level: Beginner
User Rating: By 15 Users
Compatibility: C, C++ (general), Microsoft Visual C++, Borland C++, UNIX C++
Views: 1212
 
     A Highly Efficient C program to Find whether a given number is Power of 2 or not
 

INCLUDE files:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
//INCLUDE files for :Efficient_Power_Of_2
//**************************************
#include<stdio.h>
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Efficient_Power_Of_2
// Description:A Highly Efficient C program to Find whether a given number is Power of 2 or not
// By: Balram Reddy Kakani (from psc cd)
//
// Inputs:Input is Integer. (not command line args)
//
// Returns:No Return ...
//
// Assumes:Assuming User will give Integer Input.
Using Bitwise operator makes it more faster and efficient.
Eg ... (8) & (8-1) is always 0 ...
//
// Side Effects:No Side Effects ...
//**************************************

#include <stdio.h>
int main()
{
int n;
printf( "Enter a number : ");
scanf("%d",&n);
if ( n & (n-1)) printf("\nNo");
else printf("\nYes");
return 0;
}


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.