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

There are 100 doors all are closed. The below action is taken 1) all are opened 2)all multiple of 2's are togelled ie if open close or viceversa .....100 times. What is the status of the door after 100th.

7 Answers   Vizag Steel,


The largest rubber producer in the world__________

4 Answers  


A new apartment complex purchased 60 toilets and 20 shower heads. If the price of a toilet is three times the price of a shower head, what percent of the total cost was the cost of all the shower heads?

1 Answers   Accenture,


You are driving along in your car on a wild, stormy night, it's raining heavily, when suddenly you pass by a bus stop, and you see three people waiting for a bus: An old lady who looks as if she is about to die. An old friend who once saved your life. The perfect partner you have been dreaming about. Which one would you choose to offer a ride to, knowing very well that there could only be one passenger in your car? This is a moral/ethical dilemma that was once actually used as part of a job application. * You could pick up the old lady, because she is going to die, and thus you should save her first; * or you could take the old friend because he once saved your life, and this would be the perfect chance to ! pay him back. * However, you may never be able to find your perfect mate again.

15 Answers   Syntensia, TCS,


Average of 5 number is -10 sum of 3 numbers is 16,what is the average of other two numbers?

0 Answers   Accenture,


Find the next series: AE BH CM DU?

0 Answers   CTS,


A work is done by two people in 24 minutes. One of them alone can do it in 40 minutes. How much time will the other person wiil take to complete it

7 Answers   Accenture, GVK, TCS,


A man while going dowm in a escalator(which is miving down) takes 50 steps to reach down and while going up takes 125 steps. If he goes 5 times faster upwards than downwards. What will be the total no of steps if the escalator werent moving.

13 Answers   Cadence, CSC, CTS,


7:53 8=?

2 Answers   TCS,


3,10,20,27,54,61,?

11 Answers   Assurgent, Wafer Space,


A traveler walks a certain distance. Had he gone half a kilometer an hour faster , he would have walked it in 4/5 of the time, and had he gone half a Kilometer an hour slower, he would have walked 2 ½ hr longer. What is the distance?

4 Answers   IBM, TCS,


sbi clerical previous questionpapers

0 Answers   State Bank Of India SBI,


Categories