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

Answer Posted / sujan

int n = 3;
boolean bool = true;
int reminder;
while (n >1)
{
reminder = n % 2;
if(reminder != 0)
{
bool = false;
break;
}
else
{
n = n / 2;
}
}
if (bool == true)
printf("The number is a power of two");
else
printf("The number "+ m + " is NOT A power of two");

Is This Answer Correct ?    5 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is there any possibility to create customized header file with c programming language?

617


What does void main () mean?

721


What are high level languages like C and FORTRAN also known as?

678


Write a program to show the change in position of a cursor using c

573


What does a function declared as pascal do differently?

599






How can I check whether a file exists? I want to warn the user if a requested input file is missing.

649


What is a char in c?

552


develop algorithms to add polynomials (i) in one variable

1729


Write a program to check armstrong number in c?

631


PLS U SENS ME INTERVIEW O. MY EMAIL ADD, SOFIYA.SINGH@GMAIL.COM

1700


What is the use of a conditional inclusion statement in C?

594


Write a program to find factorial of a number using recursive function.

634


What is a #include preprocessor?

610


Explain about C function prototype?

597


Write a program in c to replace any vowel in a string with z?

680