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
Answer Posted / 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 |
Post New Answer View All Answers
Radha,Geeta&Revathi went for a picnic.After a few days they forgot the date,day and month on which they went to picnic.Radha said that it was on Thursday,May 8 and Geeta said that it was Thursday May 10.Revathi said Friday Jun 8.Now one of them told all things wrongly,others one thing wrong and the last two things wrongly.If April 1st is tuesday what is the right day,date and month? thought that he should not waste his time and started moving towards his residence at the speed of 3mi/hr.On the way,he gets the coach and reaches home at 6 o'clock.How far is his residence from railway station.
There are three persons A,B,C .A shots the target 6 times out of 7 shots .B shots 4 out of 5 shots .Then what is the probability of hitting the target twice when 2 persons are selected at random.
hi had any body attended bank of interview plz........ share your experience
a man covered 28 steps in 30 seconds but he decided to move fast and covered 34 steps in 18 seconds. how many steps are there on the escalator when stationary.
in a single throw of dice ,the chance of throwing a total of 3 is
The minute hand of a clock overtakes the hour hand at intervals of 64 minutes of correct time. How much a day does the clock gain or lose?
two friends A,B are running up hill and then to get down! length if road is 440 yards A on his return journy met B goin up at 20 yards from top,A has finished the rase .5 Minuit earlier than B,then how much time A had taken to complete the rase.
Two trains move in the same direction at 50 kmph and 32 kmph respectively. A man in the slower train observes the 15 seconds elapse before the faster train completely passes by him.
In Bangalore, during income tax deduction for a single person, the percentage increased by 3% and for middle house-holders, it decreased by 3%. What can you infer?
A certain type of mixture is prepared by mixing brand A at Rs.9 a kg. with brand B at Rs.4 a kg. If the mixture is worth Rs.7 a kg., how many kgs. of brand A are needed to make 40kgs. of the mixture?
If the simple interest is 10.5 % annual and compound interest is 10 % annual, compounded annually, find the difference between the interests after 3 years on a sum of Rs. 1,000.
A cylinder is inserted in a sphere d/h = 2/3. Find the surface area of the cylinder ?
Find perimeter of a trapezium with 3 sides given and distance between parallel sides given.
Find the number WXYZ divisible by 36? i) Let the digits be5, 4,3,6 -not in that order ii) Sum of last two digits is 9 iii) Sum of middle two digits is 7->If one is sufficient then ans as A || if two is sufficient then ans as B || if all are necessary then ans as C || if nothing is needed then
a train runs first half of the distance at 40 km/hr and the remaining half at 60 km/hr. What is the average speed for the entire journey?