Function to find the given number is a power of 2 or not?

Answer Posted / swathi sharma

#include<stdio.h>
int main()
{
int num,i=1;
printf("Enter the number:");
scanf("%d", &num);
do
{
i=i*2;
if(i==num)
{
printf("\n The no.is power of 2.");
break;
}
else if(i>num)
{
printf("\n The no. is not power of 2");
break;
}
}
while(i != num);
return 0;
}

Is This Answer Correct ?    8 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What do you understand by friend-functions? How are they used?

647


Explain about the functions strcat() and strcmp()?

598


c program for searching a student details among 10 student details

1656


hw can we delete an internal node of binary search tree the internal node has child node..plz write progarm

1634


Are negative numbers true in c?

600






we called a function and passed something do it we have always passed the "values" of variables to the called function. such functions calles are called a) calls by reference b) calls by value c) calls by zero d) none of the above

638


Can true be a variable name in c?

560


What is the use of function in c?

715


Does c have enums?

603


What is function prototype?

611


Where is c used?

652


Explain how do you use a pointer to a function?

641


what is the syallabus of computer science students in group- 1?

1845


How many types of errors are there in c language? Explain

573


How do you search data in a data file using random access method?

835