Function to find the given number is a power of 2 or not?
Answer Posted / sagar bhagat
#include<stdio.h>
#include<conio.h>
void main()
{
int num,i,flag=0,temp;
clrscr();
printf("\nEnter the number=");
scanf("%d",&num);
if(num<=0)
printf("Plz enter anoter num");
else
{
temp=num;
for(i=1;(i<num) ;i++)
{
if((i*i)==temp)
{
flag=1;
break;
}
}
}
if(flag==1)
printf("\nNumber %d is in power of 2 of %d",num,i);
else
printf("\nNumber %d is not in power of 2 ",num);
getch();
}
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
Give the rules for variable declaration?
I need a sort of an approximate strcmp routine?
What is the use of a semicolon (;) at the end of every program statement?
How can I run c program?
Using functions, write a program that multiplies two arrays. Use the following functions: - Function ReadArray - Function MultiplyArrays - Function DisplayArrays
Write a program of prime number using recursion.
Write a code of a general series where the next element is the sum of last k terms.
What is wild pointer in c?
Explain what is output redirection?
What are header files why are they important?
What is const keyword in c?
Write a program to reverse a string.
Differentiate between static and dynamic modeling.
Explain what is meant by high-order and low-order bytes?
Tell me is null always defined as 0(zero)?