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

If A is travelling at 72 km per hour on a highway. B is travelling at a speed of 25 meters per second on a highway. What is the difference in their speeds in m/sec.

1140


THERE ARE 3 PILES OF BOOKS ON THE TABLE YOU NEED TO ARRANGE THEM IN THE SELF SUCH THAT 1ST BOOK OF EACH PILE GETS PLACED ON THE SELF,WHAT IS THE POSSIBLE NO OF ARRANGEMENTS

3654


In a typical motor cycle rally, every motor cycle has to reach a speed of 20 m/min within a minute and it increase its speed by 20 m/min and the sum was 1600 m/min. Four minutes later, a new motor cyclist started running in the race. After another two minutes, the motor cyclist with the speed of 400 m/min stopped due to injuries and again two new motor cyclist started running in the race. What is the current average speed?

1127


a block of ice floats on water in a beaker, as the ice melts,the water level in the beaker will

1144


Aeroplane is flying at a particular angle and latitude,after some time another latitude is given..(8 hrs later), You are asked to find the local time of the place.

1153


A simple interest amount of Rs 6000 for 6 months is Rs 600. Calculate the annual rate of interest.

1147


Given 10 alphabets out of which 5 are to be chosen. How many words can be made with atleast one repetition.

1272


Six squares of same dimension are kept side by side to make a rectangle with a perimeter of 182 cm. what is the perimeter of each square.

1179


In a fraction, if 1 is added to both the numerator at the denominator, the fraction becomes 1/2. If numerator is subtracted from the denominator, the fraction becomes 3/4. Find the fraction.

1160


one fast typist type some matter in 2hr and another slow typist type the same matter in 3hr. if both do combinely in how much time they will finish.

1165


x:y=3 and x+y=80 what is the value of y?

1250


A man shows his friend a woman sitting in a park and says that she the daughter of my grandmother's only son. What is the relation between the two

1414


I HAVE APPLIED RRB EXAM. SO IWANT TO MODEL OUESTION PAPERS (DEGREE)

2155


There are two balls touching each other circumferencically. The radius of the big ball is 4 times the diameter of the small ball.The outer small ball rotates in anticlockwise direction circumferencically over the bigger one at the rate of 16 rev/sec. The bigger wheel also rotates anticlockwise at Nrev/sec. what is 'N' for the horizontal line from the centre of small wheel always is horizontal.

1127


A man collects cigarette stubs and makes one full cigarette with every 8 stubs.If he gets 64 stubs how many full cigarettes can he smoke.

1923