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

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

1327


If a worker gets late for his work he has to pay a fine of Rs 200 on the first day and the fine increases by 25 Rs per day. If he pays a total amount of Rs 9450, for how many days did he pay for?

1350


A sales person multiplied a number and get the answer is 3, instead of that number divided by 3. what is th answer he actually has to get ?

1263


what is the largest prime number in 8 digit number?

1283


slur : speech :: smulge : ?

1477


There are two trees in a lawn. One grows at a rate 3/5 of the other in 4 years. If the total growth of trees What is the height of the smaller tree after 2 years

1318


Certain no. of men can finish a piece of work in 10 days. If however there were 10 men less it will take 10 days more for the work to be finished. How many men were there originally.

1294


what is the number whose reminder is 2 after dividing 5and also reminder is 4 after deviding 7 and reminder is 6 after deviding 9?

2318


A plane moves from 9? N40? E to 9? N40? W. If the plane starts at 10 am and takes 8 hours to reach the destination, find the local arrival time.

1527


Four circles are drawn from the corners of a square of area 49 cm2. Find the area of 4 circles outside the square (they didn't mention that circles have radius=1/2 side of a square)?

1308


Which of the following is not a valid DEFINE GDG parameter a) OWNER b)LIMIT c) SCRATCH c)ALTER

2431


In geometry, polygons with up to twelve sides have different given names; however, ______________________ if the number of sides is higher than twelve, the polygon is named by placing the suffix "gon" after the number of sides in the polygons. if the number of sides is greater than twelve, the polygon is named by placing the suffix "gon" after the number of sides in the polygons. if the number of sides is greater than twelve, name the polygon by placing the suffix "gon" after the number of sides in the polygons. if the number of sides is higher than twelve, name the polygon by placing the suffix "gon" after the number of sides in the polygons.

2218


cpahlet : shoulder :: ring : ?

1359


There are two queues at a discount store billing counter. In the first queue there are a1 customers all with b1 items in their cart, while in the second queue there are a2 customers all with b2 items in their cart. It takes t seconds to process each item and p seconds for each person to pay. A customer wishes to know which queue to join.Which one of these options gives the condition for the first queue to be the better queue to join?

1200


The distance b/w 2 places is 1000 miles and a man has a camel which eats an apple/mile. He has 3000 apples and want to transport from one to another. Camel can take 1000 apples at a time. when reaching the destination how many apples will be with him?

1277