c program to find whether a no is power of two or not.

Programming Example

Write a program to find whether a no is power of two or not.

Power of Two :- In mathematics, a power of two is a number of the form 2^n where n is an integer.

For Example :-

Input = 64

Output = 64 is the power of 2

So as we can see that 2^6 = 64. So the number 64 is the power of two.

Solution

#include <stdio.h>
#include<math.h>
int main() 
{   
	int num;
	printf("Enter Any positive integer Number: ");
	scanf("%d",&num);
	if(ceil(log2(num)) == floor(log2(num)))
	{
		printf("%d is the power of two\n",num);
	}
	else
	{
		printf("%d is not the power of two\n",num);
	}
	return 0; 
} 
Output

Enter Any positive integer Number: 32

32 is the power of two

-----------------------------------------

Enter Any positive integer Number: 10

10 is not the power of two

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Website development Company in Allahabad