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
A bike runs at the speed of 50 km/h when not serviced and runs at 60 km/h when serviced. After servicing the bike covers a certain distance in 6 h. How much time will the car take to cover the same direction?
One guy (some name) has Rs. 100/- in hand. He has to buy 100 balls. One football costs Rs. 15/, One Cricket ball costs Re. 1/- and one table tennis ball costs Rs. 0.25 He spend the whole Rs. 100/- to buy the balls. How many of each balls he bought?
two trains are 2 kms apart. Speed of one train is 20m/s and the other train is running at 30 m/s. Lengths of the trains are 200 and 300m. In how much time do the trains cross each other?
How would you measure 4 liters using jugs of 3l and 5l? Give a few solutions to this problem?
A sequence is given. You should find out error & write correct 1 2 5 10 13 26 29 48.
A store was earning 25% profit after giving a discount of almost 25%,. If they now give 10% discount then what is the profit percentage earned.
The first United States Solicitor General, Benjamin H. Bristow, __________________________ was born in 1832 and served in the Grant administration from 1874 to 1876. Earlier in his life, Bristow served as a lieutenant colonel in the 25th Kentucky Infantry was born in 1832 and had served in the Grant administration from 1874 to 1876. Earlier in his life, Bristow served as a lieutenant colonel born in 1832 and served in the Grant administration from 1874 to 1876. Earlier in his life, Bristow had served as a lieutenant colonel in the 25th Kentucky Infantry born in 1832 and appointee in the Grant administration from 1874 to 1875. Earlier in his life, Bristow served as a lieutenant colonel in the 25th Kentucky Infantry
Refer to the figure below.A ship started from P and moves at a speed of I miles per hour and another ship starts from L and moving with H miles per hour simultaneously.Where do the two ships meet? ||---g---||---h---||---i---||---j---||---k---||---l---|| PG H I J K L are the various stops in between denoted by || . The values g, h, i, j, k, l denote the distance between the ports.
Three taps A, B and C can fill a tank in 12, 15 and 20 hours respectively. If A is open all the time and B and C are open for one hour each alternately. Then the tank will be full in:
In a company 30% are supervisors and 40% employees aare male if 60% of supervisors are male what is the probability that is randomly choosen employee is a male or female?
What are all the java technical questions?
.Both A and B Alice and Bob play the following chip-off-the-table game. Given a pile of 58 chips, Alice first picks at least one chip but not all the chips. In subsequent turns, a player picks at least one chip but no more than the number picked on the previous turn by the opponent. The player to pick the last chip wins. Which of the following is true?
starting from 2 upto how many numbers we need to check whether 907 is prime or not?
Find the correct meaning of the following phrase: To bite the dust
X and Y are partners in a business. X invests 300 for 12 months and Y invested 600 for 6 months. If they gain a profit of 700 at the end of one year, what is X's share?