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

a family has 4 people. father is 10kgs.mother 10 kgs.daughter 5 kgs,son 5 kgs........the family has to cross a river to reach other side of land ..Assume they should go from A to B....the boat is limited to carry 10 kgs at a time...how will they reach?THERE IS NO SAILOR TO TAKE THEM...

2 Answers   Manhattan,


in 8*8 chess board what is the total number of squares refer odel

0 Answers   Accenture,


How many digits will be there to the right of the decimal point in the product of 95.75 and .02554 ?

0 Answers  


Argentina had football team of 22 player of which captain is from Brazilian team and goalki from European team. For remainig palayer they have picked 6 from argentinan 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 rgentinian and 6 from European. Find out no. of methods avilable for it.

3 Answers   Cognizant, CTS,


how to calculate three digit number multiplication? send me any shortcut? 235*235

1 Answers   Banking, UBA,


A circular dartboard of radius 1 foot is at a distance of 20 feet from you. You throw a dart at it and it hits the dartboard at some point Q in the circle. What is the probability that Q is closer to the center of the circle than the periphery? 0.75 1 0.5 0.25 Solution: 0.25 can someone plz explain how this answer is calculated?????

3 Answers   TCS,


A is a father of B,but B is not a son of A. Then what is the relationship among them?

25 Answers   Asian Paints, Hero MotoCorp, SAP Labs,


17) How many integers between 100 and 150, inclusive, cannot be evenly divided by 3 nor 5? a) 35 b) 27 c) 25 d) 26 e) 28

8 Answers   CTS, TCS,


Why 3 comes after 2 And 2 comes after 1 ?

8 Answers  


find the smallest no in gp whose sum is 38 and product is 1728 a. 12 b. 20 c. 8 d. none of these

4 Answers   Infotech, Satyam,


10.If 100 ! = 100 x 99 x 98 x … x 2 x 1, the maximum power of 20 which will divide 100 ! is 1] 21 2] 22 3] 23 4] 24 Plz Explain

3 Answers   Hewitt, IBM,


An apple seller is having some apples. He is selling half of the apple what he has plus half the apple to the first customer. In the same way he sells the remaining apple to 7 customers. After selling to 7 customers, he has no apples with him.

0 Answers   Accenture,


Categories