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

can anyone please tell me the written test pattern for FIDELITY (for incampus)for freshers......

0 Answers   CAT, TCS,


2. The following list shows the preference of 102 people at a wine-tasting party: 99 like Spanada ,94 like Ripple and Boone’s 96 like Ripple,96 like Spanasa and Boone’s 99 like Boone’s Farm Apple Wine ,93 like all three 95 like Spanada and Ripple How many people prefer: a) none of the three? ______________ b) Spanada, but not Ripple? ______________ c) anything but Boone’s Farm? ______________ d) exactly two kinds of wine? ______________

2 Answers  


Y catches 5 times more fishes than X. If total number of fishes caught by X and Y is 48, then number of fishes caught by X?

0 Answers   BPCL Bharat Petroleum, Sonata,


aptitude questions

1 Answers   HCL, Solartis, TCL, TCS, XL Dynamics,


23*2

1 Answers  


When DB2 is run in IMS environment an application can access data in a) Only DB2 database b) Only IMS database c) Both DB2 & IMS databases d) None of the above

0 Answers  


Please,let me know the RRB question papers for Junior Engg.Electrical & Electronics Engg post.Thank You

0 Answers   PreludeSys,


bank IT or PO qusetion papers

0 Answers  


Two coins one with HEAD IN BOTH SIDES and the other coin HEAD IN ONE SIDE AND TAIL IN THE OTHER SIDE is in a box,a coin is taken at random and FOUND HEAD IN ONE SIDE .what is the probability that THE OTHER SIDE IS HEAD?

0 Answers   Accenture,


A rectangular tank can hold m litres of milk. Find how many litres of milk can a tank hold when all its dimensions are doubled?

0 Answers   Cap Gemini,


If y/x = 1/3 and x + 2y = 10, then x is

8 Answers   Paladon,


what do you know about banking industry?

2 Answers  


Categories