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 |
can anyone please tell me the written test pattern for FIDELITY (for incampus)for freshers......
2. The following list shows the preference of 102 people at a wine-tasting party: 99 like Spanada ,94 like Ripple and Boone’s 96 like Ripple,96 like Spanasa and Boone’s 99 like Boone’s Farm Apple Wine ,93 like all three 95 like Spanada and Ripple How many people prefer: a) none of the three? ______________ b) Spanada, but not Ripple? ______________ c) anything but Boone’s Farm? ______________ d) exactly two kinds of wine? ______________
Y catches 5 times more fishes than X. If total number of fishes caught by X and Y is 48, then number of fishes caught by X?
0 Answers BPCL Bharat Petroleum, Sonata,
aptitude questions
1 Answers HCL, Solartis, TCL, TCS, XL Dynamics,
23*2
When DB2 is run in IMS environment an application can access data in a) Only DB2 database b) Only IMS database c) Both DB2 & IMS databases d) None of the above
Please,let me know the RRB question papers for Junior Engg.Electrical & Electronics Engg post.Thank You
bank IT or PO qusetion papers
Two coins one with HEAD IN BOTH SIDES and the other coin HEAD IN ONE SIDE AND TAIL IN THE OTHER SIDE is in a box,a coin is taken at random and FOUND HEAD IN ONE SIDE .what is the probability that THE OTHER SIDE IS HEAD?
A rectangular tank can hold m litres of milk. Find how many litres of milk can a tank hold when all its dimensions are doubled?
If y/x = 1/3 and x + 2y = 10, then x is
what do you know about banking industry?