Function to find the given number is a power of 2 or not?
Answer Posted / s.v.prasad reddy,lifetree conv
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int num,i=0,flag;
clrscr();
printf("\nEnter the number:=");
scanf("%d",&num);
if(num==0 || num==1 || (num%2)!=0) /* Validation Part */
{
printf("\n We can't express the given number to power
of 2");
return;
}
for(;;}
{
if(pow(2,i)==num)
{
flag=1;
break;
}
if(pow(2,i)>num)
{
flag=0;
break;
}
i++;
}
if(falg==1)
printf("\n %d number is 2 power of %d",num,i);
else
printf("\n%d number can't be expressed as power of 2",num);
getch();
}
| Is This Answer Correct ? | 3 Yes | 4 No |
Post New Answer View All Answers
What is scanf () in c?
What is a structure and why it is used?
What does dm mean sexually?
In this assignment you are asked to write a multithreaded program to find the duplicates in an array of 10 million integers. The integers are between -5000,000 to 5000,000 and are generated randomly. Use 10 threads, each thread works on 1000,000 integers. Compare the time needed to accomplish the task with single thread of execution program. Do not include the time to fill the array with integers in the execution time.
What does & mean in scanf?
What are header files and explain what are its uses in c programming?
What is structure in c definition?
Why does notstrcat(string, "!");Work?
What does char * * argv mean in c?
What is function definition in c?
What's a good way to check for "close enough" floating-point equality?
Give basis knowledge of web designing ...
What is the significance of scope resolution operator?
What is volatile variable in c?
What is main () in c?