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 |
If a square is formed by the diagonal of the square as an edge, what is the ratio between the area?
if u r traveling from Mumbai to banglore and return back .To find the speed of the car which of the following r needed. a)the distance between them. b)time taken c)avg speed towards Mumbai and the avg speed towards banglore. Choices: 1)a only. 2)a and b 3) a,b,c 4)b only 5) c only ( ans not in order)
sir how should i prepare for andhra bank clerical post examination?(i mean which book i've to follw & how)
2435 ? 24 = 24? (a) 2.5 (b) 3.5 (c) 2 (d) 3 (e) None of these
5 Answers Bank Exams, IBM, IEG, Skylark, State Bank Of India SBI,
The cycle has following specifications: The rear derailer is on the 14 tooth gear and the front derailer is on the 52 tooth gear. The rear gear has 14 teeth. The diameter of the rear wheel is 27". If a cyclist pedals at 75 revolutions per minute, then what will be the speed achieved?
what would be the next number in the sequence 1,2,10,4,3,14,9,5, ?
The house is big and lovely but since nobody uses it it is pretty much a white Elephant What does White Elephant mean?
i got good 88% and 94% in 10th and 12th respectively.but now in engineering im getting in 70's.so suppose if they ask why have your academic performance went down in that case what should i tell??
What is the factor of x-3.
please give me some solved question papers for entrance examination on banks clerk
what is mean by aptitude test? how to write this paper?
mention your extra-curricular interest. Which do you actively pursue? how do you see these developing in the future?