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

Find the value of @@+25-++@16, where @ denotes "square" and + denotes "square root".

2596


A fuel dealer mixes two brands of fuel which cost in the ratio 2:3 A solution of 30% Brand A with Brand B yields profit of 10% when sold at RS 297. What is cost of brand B?

2015


Zulus always speak truth and Hutus always speak lies. There are three persons A,B&C. A met B and says " I am a Zulu or I am Hutu". We don't know what exactly he said. then B meets C and says to c that " A is a Zulu ". Then C replied " No, A is a Hutu ". Who must be a Zulu ?

1509


If TAFJHH is coded as RBEKGI then RBDJK can be coded as ---------

3804


3 red and 4 blue balls are in a basket. A member of PPTeam is drawing balls from the basket.What is the probablity of getting the 3 red balls simultaneously?

1358


A moves 3 kms east from his starting point . He then travels 5 kms north. From that point he moves 8 kms east.How far is A from his starting point?

1441


There are 200 employees in a company. An external vendor is chosen to Serve coffee twice a day. 100 coffee cups were offered by the company but as an incentive to have the cups in tact at the end of the day, the company offered 30 paise for every cup remained safely and charged 90 paise for every broken cup. At an end of a day, the vendor received Rs. 24. How many cups did the vendor break? 10, 20, 8, 5?

2281


Find out the Simple Interest paid for a sum of $4000 at the rate of 8% per annum for 3 months.

1477


in a mixture, R is 2 parts, S is 1 part. in order to make S to 25% of the mixture, howmuch R is to be added

1232


f(f(x))=81 THEN VALUE OF X=

1340


Number of digits with a 2 in them between 100 and 400?

1312


Find the next letter in the series Q,W,E,R,T,--

1296


A man has Rs 2. He wins or loses Re 1 at a time. If he wins he gets Re 1 and if he loses the game he loses Re 1. He can loose only 5 times. He is out of the game if he earns Rs 5.Find the number of ways in which this is possible?

1342


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

2211


. Which of the following is not a VSAM dataset. a. KSDS b. RRDS c. LSDS d. ESDS

2887