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
A cycled from P to Q at 10 kmph and returned at the rate of 9 kmph. B cycled both ways at 12 kmph. In the whole journey B took 10 minutes less than A. Find the distance between P and Q.
A vegetable seller sells his vegetables at the rate of Rs. 9 kg and thereby incurs a loss of 20%. If he had to make a profit of 5%, at what price per Kg should he sell his vegetables?
12 Blacksox and 12 Whitesox mixed in a box,a pair of sox is picked at a time,in which pick how many pick ,to get the right pair(black&black or white&white)?
The cost of 16 articles is equal to sell price of 12 articles. The gain percent is ?
sir , i hv done 85 correct question in ssc cgl-tier-i 2010 after checking through my source which is correct , tell me whether i m eleigible for tier-ii or not charan , jalandhar
The mean and the variance of a binomial distribution are 4 and 2 respectively. Then the probability of 2 successes is?
If x,y,z are chosen frm -3,1/2,2 what is the largest value of (x/y)*z*z
In a car wheel, two spokes cover 15 degree. Then for the entire car,how many spokes are there?
there are 3 nurses and they work altogether only once in a week. no nurse is called to work for 3 consecutive days. nurse 1 is off on tueseday,thursday and sunday. nurse 2 is off on saturday. nurse 3 is off on thursday, sunday. no two nurses are off more than once a week. find the day on which all the 3 nurses were on work.
a grandfather has 5 sons and daughters and grandchildren.they have to be arranged in a row such that the first 4 seats and last four seats are to be taken by grandchildren and the grandfather would not sit adjacent to any of the grandchildren.
There are 1, 40, 00, 000 pencils of lengths ranging from 3 to 6 inches and are put up straight. The average length of 80% of pencils is 5 inches. Calculate the total length spanned by the pencils.
A man has 2 cows of total cost 200 rupees. He sold them for 210. For 1 cow he had a profit of 10% and for the other he had a loss of 10%. What is the price of each cow?
A tailor has 37.5 metres of cloth and he has to make 8 piecesout of a metre of cloth. How many pieces can he make out of this cloth?
Find the smallest number which leaves 22,35, 48 and 61 as remainders when divided by 26, 39, 52 and 65 respectively.
In a 10 digit number, if the 1st digit number is the number of ones,2nd digit number is the number of twos, and ... so on. 10th digit is the number of zeroes,then find the number