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
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 |
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 |
BEAT is written as GIDV; SOUP may written as :
Total number of wheels of bicycles & 4 wheeled vechicles is 38. How many bicycles are there?
There are 9 balls of these one is defective. Find the minimum no. of chances of finding the defective one.
Find the hypotenuse of a right angle isoceles triangle whose area is 50.
(Momentum*Velocity)/(Acceleration * distance ) find units.
3x^2-5x+4=6, what is x?
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=?
If a square is formed by the diagonal of the square as an edge, what is the ratio between the area?
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?
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?
Complete the series..2 2 12 12 30 30 ?
What is the 8th term in the series 1,4, 9, 25, 35, 63, . . . ?