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 |
Susan wants to put up fencing around three sides of her rectangular yard and leave a side of 20 feet unfenced. If the yard has an area of 680 square feet, how many feet of fencing does she need?
If the equation x2 - 3x + a = 0 has the roots (0,1) then value of a is ?
Information about projects iniliated by the govt?
The mean of 100 bags was found to be 30. What will be the correct mean if at the time of calculation two bags were wrongly taken as 32 and 12 instead of 23 and 11?
Two planes take off at the same exact moment. They are flying across the Atlantic Ocean. One leaves New York and is flying to Paris at 800 km/hr. The other leaves Paris and is flying to New York at only 750 km/hr ( because of a strong head wind ). Which one will be closer to Paris when they meet?
how many rivers are present in sindh?
Find the next series: AE BH CM DU?
X is 6 years younger to Y. X's father is a businessman who invested 10000/- at 8% rate of interest n obtained his amount after 10 years. Y's father is a job holder who invested around 20000 at 2% rate n obtained his amount after 20 years. Now Compounded both of them get around ABC After 3 years the ratio of ages of X n Y is 1 :2. Now X's father is 20 years older to Y n Y’ father is 30 years more than X. After 20 years again X's mother asks X’s father to purchase a LCD TV which costs around 45000/-. what is the age of X n Y together?
From 7:00 AM to 11:00 AM it rained 2.25 inches. At 11:00 AM the rain increased to fall at a rate of 1.25 in. every two hours. How many inches of rain landed on the ground by 5:00 PM?
In a sports club with 30 members, 17 play badminton and 19 play tennis and 2 do not play either. How many members play both badminton and tennis
There are twelve consecutive flags at an equal interval of distance. A man passes the 8th flag in 8 seconds. How many more seconds will he take to pass the remaining 4 flags?
Please send the SBI Clerical job Question paper set with answer
7 Answers Ram Infotech, State Bank Of India SBI,