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 clock showing 6 o'clock takes 30 secs to strike 6 times.How long will it take to strike 12 at midnight?
f(X)=4f(X-1) THEN VALUE OF X=
A person with some money spends1/3 for cloths, 1/5 of the remaining for food and 1/4 of the remaining for travel. He is left with Rs 100/- . How much did he have with him in the beginning ?
Find sum of 3 + 5/(1+22) + 7/(1 + 22 + 32) + ......
If Ever + Since = Darwin then D + a + r + w + i + n is ?
There are following denominations of money: 1, 2, 5, 10, 20, 50, and 100 paise. Alex has as twice mony as David, who has as twice as Bindya, who again has as twice money as Charles. Each has two coins in hand. Which coins Bindya has?
electrical question in diploma level
A number, when it is divided by 8 it gives a remainder 3 and is divisible by both 3 and 5. Find the number.
Sum of slopes of 2 perpendicular st. lines is given. Find the pair of lines from the given set of options which satisfy the above condition?
Sir iam going to write exam for the post of Officers under training in APSRTC. Please send me the model papers to my mail ganjiramji@gmail.com
A plane starts from a place A , it goes 1000 kms south then 1000km east then 1000 km north and 1000km west, what is it distance from the starting place? ans.same starting place.
please let me know the minimum qualifying marks in screening test of group1 2010 to be eligible for group1 main exam.
The sum of the series 1 + 1(1+1/n) + 3(1+1/n)2 + ..... is equal to?
I and two of my friends were playing a game. For each win I get Rs 3. Totally I had three wins. Player 2 got Rs.9 and player 3 got Rs 12. How many games had been played?
Argentina had football team of 22 player of which captain is from Brazilian team and goalki from European team. For remaining player they have picked 6 from Argentinean and 14 from European. Now for a team of 11 they must have goalki and captain so out of 9 now they plan to select 3 from Argentinean and 6 from European. Find out no. Of methods available for it