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
Do you have any idea about the use of "auto" keyword?
if a is an integer variable, a=5/2; will return a value a) 2.5 b) 3 c) 2 d) 0
What standard functions are available to manipulate strings?
What is main () in c language?
How do you initialize pointer variables?
What are extern variables in c?
How can you determine the size of an allocated portion of memory?
What is register variable in c language?
why wipro wase
Explain which function in c can be used to append a string to another string?
What is #pragma statements?
program to find out date after adding 31 days to a date in the month of febraury also consider the leap year
Subtract Two Number Without Using Subtraction Operator
typedef struct{ char *; nodeptr next; } * nodeptr ; What does nodeptr stand for?
What are the primitive data types in c?