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 |
a family has 4 people. father is 10kgs.mother 10 kgs.daughter 5 kgs,son 5 kgs........the family has to cross a river to reach other side of land ..Assume they should go from A to B....the boat is limited to carry 10 kgs at a time...how will they reach?THERE IS NO SAILOR TO TAKE THEM...
in 8*8 chess board what is the total number of squares refer odel
How many digits will be there to the right of the decimal point in the product of 95.75 and .02554 ?
Argentina had football team of 22 player of which captain is from Brazilian team and goalki from European team. For remainig palayer they have picked 6 from argentinan 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 rgentinian and 6 from European. Find out no. of methods avilable for it.
how to calculate three digit number multiplication? send me any shortcut? 235*235
A circular dartboard of radius 1 foot is at a distance of 20 feet from you. You throw a dart at it and it hits the dartboard at some point Q in the circle. What is the probability that Q is closer to the center of the circle than the periphery? 0.75 1 0.5 0.25 Solution: 0.25 can someone plz explain how this answer is calculated?????
A is a father of B,but B is not a son of A. Then what is the relationship among them?
25 Answers Asian Paints, Hero MotoCorp, SAP Labs,
17) How many integers between 100 and 150, inclusive, cannot be evenly divided by 3 nor 5? a) 35 b) 27 c) 25 d) 26 e) 28
Why 3 comes after 2 And 2 comes after 1 ?
find the smallest no in gp whose sum is 38 and product is 1728 a. 12 b. 20 c. 8 d. none of these
10.If 100 ! = 100 x 99 x 98 x … x 2 x 1, the maximum power of 20 which will divide 100 ! is 1] 21 2] 22 3] 23 4] 24 Plz Explain
An apple seller is having some apples. He is selling half of the apple what he has plus half the apple to the first customer. In the same way he sells the remaining apple to 7 customers. After selling to 7 customers, he has no apples with him.