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 |
Area if square increase by 69% find sides % increased by?
In Asia which country is the landlocked country? 1. Malaysia 2. Singapore 3. South east asia 4. Russia
1, 11, 21, 1211, 111221, 312211, . . . . . what is the next term in the series?
A solid cube of each side 8cms, has been painted red , blue , black on pairs of opposite faces.It is then cut into cubical blocks of each side 2cms.
In a certain format TUBUJPO is coded as STATION. The code of which string is FILTER?
for cube and sphere 3 views are similarly draw one such figure?
Each side of a rectangle is increased by 100% .By what percentage does the area increase?
0 Answers 3i Infotech, Canara Bank, Geodesic,
. One train leaves Bangalore at 15 kmp heading for Mysore. Another train leaves from Mysore at 20kmp heading for Bangalore on the same track. If a bird, flying at 25kmp, leaves from Bangalore at the same time as the train and flies back and forth between the two trains until they collide, how far will the bird have traveled?
An orange vendor makes a profit of 20 % by selling oranges at a certain price. If he charges Rs. 1.2 higher per orange he would gain 40 %. Find the original price at which he sold an orange.
the largest river of asia is
rita bought dress at 3000 sold it to sita for 25 % profit, sita didnt like it sold it back to rita for 10 % loss. wat % of profit rita got during the transaction ?
can any1 inform me abt office work aptitude?????????