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

BEAT is written as GIDV; SOUP may written as :

3 Answers   ISRO,


Total number of wheels of bicycles & 4 wheeled vechicles is 38. How many bicycles are there?

6 Answers   TCS,


There are 9 balls of these one is defective. Find the minimum no. of chances of finding the defective one.

0 Answers   Accenture,


Find the hypotenuse of a right angle isoceles triangle whose area is 50.

0 Answers   Citicorp,


(Momentum*Velocity)/(Acceleration * distance ) find units.

0 Answers   Accenture, BSNL,






3x^2-5x+4=6, what is x?

3 Answers   3D PLM,


f(X)= 2X-1 + f(X-1) if X is not equal to zero and if f(X=0)=0, If f(X)=4f(X-1) then the value of X=?

0 Answers   CTS,


If a square is formed by the diagonal of the square as an edge, what is the ratio between the area?

0 Answers   Hexaware,


How many such pairs of digits are there in the number 53146827 each of which has as many digits between them in the number as when the digits are arranged in ascending order within the number?

1 Answers  


If Rs 20/- is available to pay for typing a research report & typist A produces 42 pages and typist B produces 28 pages.How much should typist A receive?

5 Answers   L&T, TCS,


Complete the series..2 2 12 12 30 30 ?

0 Answers   HCL, Infosys,


What is the 8th term in the series 1,4, 9, 25, 35, 63, . . . ?

1 Answers   HCL,


Categories