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
Explain which function in c can be used to append a string to another string?
What does static variable mean in c?
What is gets() function?
How can I call system when parameters (filenames, etc.) Of the executed command arent known until run time?
What is the difference between struct and union in C?
Do you know the use of 'auto' keyword?
What are lookup tables in c?
What is the use of getchar functions?
How can you restore a redirected standard stream?
Why doesnt the call scanf work?
Tell me when is a void pointer used?
What is the method to save data in stack data structure type?
Explain two-dimensional array.
Write a C program to help a HiFi’s Restaurant automate its breakfast billing system. Your assignment should implement the following items: a. Show the customer the different breakfast items offered by the HiFi’s Restaurant. b. Allow the customer to select more than one item from the menu. c. Calculate and print the bill to the customer. d. Produce a report to present your complete program and show more sample output. Assume that the HiFi’s Restaurant offers the following breakfast menu: Plain Egg $2.50 Bacon and Egg $3.45 Muffin $2.20 French Toast $2.95 Fruit Basket $3.45 Cereal $0.70 Coffee $1.50 Tea $1.80
write a program fibonacci series and palindrome program in c