Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

A clock showing 6 o'clock takes 30 secs to strike 6 times.How long will it take to strike 12 at midnight?

1679


f(X)=4f(X-1) THEN VALUE OF X=

1225


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 ?

1417


Find sum of 3 + 5/(1+22) + 7/(1 + 22 + 32) + ......

1225


If Ever + Since = Darwin then D + a + r + w + i + n is ?

4163


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?

1297


electrical question in diploma level

7838


A number, when it is divided by 8 it gives a remainder 3 and is divisible by both 3 and 5. Find the number.

1230


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?

1301


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

2298


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.

1608


please let me know the minimum qualifying marks in screening test of group1 2010 to be eligible for group1 main exam.

2911


The sum of the series 1 + 1(1+1/n) + 3(1+1/n)2 + ..... is equal to?

1214


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?

2280


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

1364