Function to find the given number is a power of 2 or not?
Answer Posted / udhaya
Find if the given number is a power of 2.
//include math.h
void main()
{
int n,logval,powval;
printf("Enter a number to find whether it is s power of
2\n");
scanf("%d",&n);
logval=log(n)/log(2);
powval=pow(2,logval);
if(powval==n)
printf("The number is a power of 2");
else
printf("The number is not a power of 2");
getch();
}
| Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
Can 'this' pointer by used in the constructor?
Tell me what is the purpose of 'register' keyword in c language?
How can a process change an environment variable in its caller?
p*=(++q)++*--p when p=q=1 while(q<=6)
code for replace tabs with equivalent number of blanks
A banker has a seif with a cipher. Not to forget the cipher, he wants to write it coded as following: each digit to be replaced with the difference of 9 with the current digit. The banker chose a cipher. Decipher it knowing the cipher starts with a digit different than 9. I need to write a program that takes the cipher from the keyboard and prints the new cipher. I thought of the following: Take the input from the keyboard and put it into a string or an array. Go through the object with a for and for each digit other than the first, substract it from 9 and add it to another variable. Print the new variable. Theoretically I thought of it but I don't know much C. Could you give me any kind of hint, whether I am on the right track or not?
Devise a program that inputs a 3 digit number n and finds out whether the number is prime or not. Find out its factors.
What is the easiest sorting method to use?
What is the meaning of && in c?
What is bash c?
Explain what is the best way to comment out a section of code that contains comments?
int i=3; this declaration tells the C compiler to a) reserve space in memory to hold the integer value b) associate the name i with this memory location c) store the value 3 at this location d) all the above
What are 3 types of structures?
hi send me sample aptitude papers of cts?
What is the usage of the pointer in c?