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

Area if square increase by 69% find sides % increased by?

3 Answers   3D PLM,


In Asia which country is the landlocked country? 1. Malaysia 2. Singapore 3. South east asia 4. Russia

3 Answers   RRB,


1, 11, 21, 1211, 111221, 312211, . . . . . what is the next term in the series?

0 Answers   HCL, Infosys,


A solid cube of each side 8cms, has been painted red , blue , black on pairs of opposite faces.It is then cut into cubical blocks of each side 2cms.

1 Answers   CTS,


In a certain format TUBUJPO is coded as STATION. The code of which string is FILTER?

1 Answers   Accenture,


for cube and sphere 3 views are similarly draw one such figure?

2 Answers   Geometric Software,


Each side of a rectangle is increased by 100% .By what percentage does the area increase?

0 Answers   3i Infotech, Canara Bank, Geodesic,


. One train leaves Bangalore at 15 kmp heading for Mysore. Another train leaves from Mysore at 20kmp heading for Bangalore on the same track. If a bird, flying at 25kmp, leaves from Bangalore at the same time as the train and flies back and forth between the two trains until they collide, how far will the bird have traveled?

4 Answers   Wipro,


An orange vendor makes a profit of 20 % by selling oranges at a certain price. If he charges Rs. 1.2 higher per orange he would gain 40 %. Find the original price at which he sold an orange.

1 Answers   John Deere,


the largest river of asia is

4 Answers  


rita bought dress at 3000 sold it to sita for 25 % profit, sita didnt like it sold it back to rita for 10 % loss. wat % of profit rita got during the transaction ?

8 Answers   Amdocs,


can any1 inform me abt office work aptitude?????????

1 Answers   ACS,


Categories