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

Tell us about ur self?

5 Answers   Chevron, IOCL, Kuwait University,


7,8,12,21,37,?

9 Answers  


Can Anybody post me the Previous Question papers for the stream of CSE. Technical and aptitude questions please.... And any suggestions to prepare for HAL examinationa and time management also. Regards, RAKESH.B

1 Answers  


How many mashes are there in 1 square meter of wire gauge if each mesh is 8mm long and 5mm wide ?

0 Answers   Mu Sigma,


a person is doing job from his earning he spents1/4 th of the salary for travelling,1/5 for his personal expenses.and rs 50 he will be depositing in the bank.what is his total salary?

6 Answers  


Argentina had football team of 22 player of which captain is from Brazilian team and goalki from European team. For remaining player they have picked 6 from Argentinean 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 Argentinean and 6 from European. Find out no. Of methods available for it

0 Answers   Cognizant,


Find the next series of 1,2,2,4,8,?

0 Answers   Infosys,


Find the number WXYZ divisible by 36? i) Let the digits be5, 4,3,6 -not in that order ii) Sum of last two digits is 9 iii) Sum of middle two digits is 7->If one is sufficient then ans as A || if two is sufficient then ans as B || if all are necessary then ans as C || if nothing is needed then

0 Answers   Accenture,


3. Given 1000 bottles of juice, one of them contains poison and tastes bitter. Spot the spoiled bottle in minimum sips?

10 Answers   Microsoft, Wipro,


Complete the series 2, 7, 24, 77,__ (hint: 2*12= 24, 7*11= 77, therefore 24*10= 240)

0 Answers   TCS,


If the product of three consecutive int is 210,then sum of the two smaller ints is:

0 Answers   Verifone,


If a man buys 1 lt of milk for Rs.12 and mixes it with 20% water and sells it for Rs.15, then what is the percentage of gain?

0 Answers   3i Infotech, Amazon, Canara Bank, Mu Sigma,


Categories