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 person goes 4/5 of his usual speed reaches 10 min late to his destinaton, time taken?
A lady has fine gloves and hats in her closet- 25blue, 7 red, and 9 yellow. The lights are out and it is totally dark. In spite of the darkness, she can make out the difference between a hat and a glove. She takes out an item out of the closet only if she is sure that if it is a glove. How many gloves must she take out to make sure she has a pair of each color?
hai team members pls send sbi bank clerk exam model question paper to my email id faruque_mullick@yahoo.co.in
The minimum number of digits required to form every number which is greater than 900 and less than 9,000 is:
It's 2PM on a sunny Sunday afternoon in the Bay Area. You're minutes from the Pacific Ocean, redwood forest hiking trails and world class cultural attractions. What do you do?
3 Answers Google, IIT, Jaypee,
In a party there are women and cats.There are 18 heads and 72 legs altogether. How many women and cats?
Ramesh working alone on a job takes 12 days more than what he would have taken if Suresh had worked along with him while Suresh working alone on the same job takes 27 days more than what he would have taken if Ramesh had worked along with him. Find the time that both of them would take together to do the job.
hello i need sample test papers for SBI probationary officer 2008...can any 1 who knws send me?????send me to surjit_casper2000@yahoo.com...plssssssssss its very urgent....lookin for the reply...
10men and 10 women are there, they dance with each other, is there possibility that 2 men are dancing with same women and vice versa?
Find the Series number: 2,5,9,19,37,..
A works thrice as much as B. If A takes 60 days less than B to do a work then find the number of days it would take to complete the work if both work together?
0 Answers 3i Infotech, Canara Bank, EDS,
You have 5 jars of pills. Each pill weighs 10 gram, except for contaminated pills contained in one jar, where each pill weighs 9 gm. Given a scale, how could you tell which jar had the contaminated pills in just one measurement?