Ques--Input a number and then find the next higher number
such that for both the number (inputted and the next higher
number)
in binary representation contains equal number os ones.
Example:
Input:3(0000000000000011)
Ouput:5(0000000000000101)
I want a solution in C/C++ language
Answer Posted / satish pandey
public class count {
public static void main(String a[])
{
int num=15,test=0,count,res=0,temp;
int check=num+1;
do
{
if(num%2==1)
{
res++;
}
num=num/2;
}while(num!=0);
while(test!=1)
{count=0;
temp=check;
do
{
if(temp%2==1)
{
count++;
}
temp=temp/2;
}while(temp!=0);
if(count==res)
{
test=1;
break;
}
else
{
check++;
test=0;
}
}
System.out.println("Next Number is = "+check);
}
}
| Is This Answer Correct ? | 6 Yes | 2 No |
Post New Answer View All Answers
Find the next three terms of the series; 1, 4, 9, 18, 35 - - - - -
One rectangular plate with lenght 8 inches, breadth 11inches and 2 inches thickness is there. What is the length of the circular rod with diameter 8 inches and equal to volume of rectangular plate?
Ajay and Vijay ave their salaries in the ratio of 2:3. If each of their salaries are increased by Rs 4000, the new ration comes to be 40:57. How much is the present salary of Vijay?
8 persons A,B,C,D,E,F,G,H are sitting in a round dining table.some arrangement was given and position of H was asked.I don't remember the question exactly.
Why RSD of area limit is 15?
In Bangalore, during income tax deduction for a single person, the percentage increased by 3% and for middle house-holders, it decreased by 3%. What can you infer?
20% of a 6 litre solution and 60% of 4 litre solution are mixed. What percentage of the mixture of solution ?
Everyday in his business a merchant had to weigh amounts from 1 kg to 121kgs, to the nearest kg.What are the minimum number of weight required and how heavy should they be?
What is the selling price of can cost selling price of .. cost .. is Rs 60 ,10% profit over selling price ?
Three men goes to a hotel to stay ,the clerk says $30 per room/day so all the three plans to stay in one room so each pays $10.After some time the clerk realises that he made a mistake of collecting $30 but the room cost only $25,there fore he decides to return $5 to them so he calls the room boy and gives him $5 asking him to return. The room boy keeps $2 with him and he returns only $3($1 for each). Now Totally all have paid $9 each($27)+room boy $2 which is equal to $27.where did $1 go,who has made the mistake?
Draw venn diagram relating rhombus, quadrilateral & polygon
Rohan bought some rice at Rs. 10 per kilogram. He buys 2 kg rice from a ration store at the rate of Rs. 8 per kilogram. He mixes the two type of rice and sells at Rs. 11 per kilogram. He makes 25% profit. What is the ratio of non-ration to ration rice?
A person has Rs 100/- in his pocket, he can as 25 pencils or 15books. He kept 15% of the money for travelling expenses and purchased 5 ncils.So how many books he can purchase with the remaining money.
low temperature at the night in a city is 1/3 more than ½ hinge as higher temperature in a day. sum of the low temp and higherst temp is 100C. then what is the low temperature
Dr. Martin A. Tidball, along with colleagues at two universities, are working on uncovering the mysteries of glucose uptake, a discovery of new details about active ATP transport, and a drug to enhance facilitated diffusion. are working hard to uncover the mysteries of glucose uptake, discover new details about active ATP transport, and enhance facilitated diffusion with the help of a drug is working on uncovering the mysteries of glucose uptake, discovering new details about ATP transport, and enhancing facilitated diffusion via a drug is working to uncover the mysteries of glucose uptake, discover new details about active ATP transport, and enhancing facilitated diffusion with the help of a drug are working on uncovering the mysteries of glucose uptake, a discovery of new details about active ATP transport, and a drug to enhance facilitated diffusion