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

Answers were Sorted based on User's Feedback



Ques--Input a number and then find the next higher number such that for both the number (inputted a..

Answer / 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

Ques--Input a number and then find the next higher number such that for both the number (inputted a..

Answer / satish pandey (gbpuat pantnaga

IN C LANGUAGE

void main()
{
int num,test=0,count,res=0,temp;
printf("\n Enetr the number ");
scanf("%d",&num);
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;
}
}
printf("Next Number is = %d",check);

}

Is This Answer Correct ?    7 Yes 3 No

Post New Answer

More General Aptitude Interview Questions

If a square is formed by the diagonal of the square as an edge, what is the ratio between the area?

0 Answers   Hexaware,


if u r traveling from Mumbai to banglore and return back .To find the speed of the car which of the following r needed. a)the distance between them. b)time taken c)avg speed towards Mumbai and the avg speed towards banglore. Choices: 1)a only. 2)a and b 3) a,b,c 4)b only 5) c only ( ans not in order)

2 Answers   CTS,


sir how should i prepare for andhra bank clerical post examination?(i mean which book i've to follw & how)

0 Answers  


2435 ? 24 = 24? (a) 2.5 (b) 3.5 (c) 2 (d) 3 (e) None of these

5 Answers   Bank Exams, IBM, IEG, Skylark, State Bank Of India SBI,


The cycle has following specifications: The rear derailer is on the 14 tooth gear and the front derailer is on the 52 tooth gear. The rear gear has 14 teeth. The diameter of the rear wheel is 27". If a cyclist pedals at 75 revolutions per minute, then what will be the speed achieved?

0 Answers   Cap Gemini,


what would be the next number in the sequence 1,2,10,4,3,14,9,5, ?

3 Answers  


The house is big and lovely but since nobody uses it it is pretty much a white Elephant What does White Elephant mean?

0 Answers   Changepond,


i got good 88% and 94% in 10th and 12th respectively.but now in engineering im getting in 70's.so suppose if they ask why have your academic performance went down in that case what should i tell??

4 Answers  


What is the factor of x-3.

5 Answers  


please give me some solved question papers for entrance examination on banks clerk

2 Answers  


what is mean by aptitude test? how to write this paper?

0 Answers   Infosys,


mention your extra-curricular interest. Which do you actively pursue? how do you see these developing in the future?

0 Answers   Nalco,


Categories