Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

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.

1368


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?

1518


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)?

1191


The cost of 16 articles is equal to sell price of 12 articles. The gain percent is ?

1386


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

2287


The mean and the variance of a binomial distribution are 4 and 2 respectively. Then the probability of 2 successes is?

1178


If x,y,z are chosen frm -3,1/2,2 what is the largest value of (x/y)*z*z

1225


In a car wheel, two spokes cover 15 degree. Then for the entire car,how many spokes are there?

1286


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.

1626


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.

2935


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.

1857


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?

1451


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?

1198


Find the smallest number which leaves 22,35, 48 and 61 as remainders when divided by 26, 39, 52 and 65 respectively.

1891


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

1263