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
How can I delete a file?
What are the disadvantages of c language?
What is the difference between union and anonymous union?
If I have a char * variable pointing to the name of a function ..
Is c programming hard?
console I/O functions means a) the I/O operations done on disk b) the I/O operations done in all parts c) the input given through keyboard is displayed VDU screen d) none of the above
difference between native and cross compilers
write a program in C that prompts the user for today's date,tomorrow's date and display the results.Use structures for today's date,tomorrow's date and an array to hold the days for each month of the year.
What is pass by reference in functions?
What does static variable mean in c?
What are the general description for loop statement and available loop types in c?
An arrangement of information in memory in such a way that it can be easily accessed and processed by a programming language a) string b) data structure c) pointers d) array
Why we use void main in c?
What is variable in c example?
Explain what math functions are available for integers? For floating point?