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 |
Tell us about ur self?
5 Answers Chevron, IOCL, Kuwait University,
7,8,12,21,37,?
Can Anybody post me the Previous Question papers for the stream of CSE. Technical and aptitude questions please.... And any suggestions to prepare for HAL examinationa and time management also. Regards, RAKESH.B
How many mashes are there in 1 square meter of wire gauge if each mesh is 8mm long and 5mm wide ?
a person is doing job from his earning he spents1/4 th of the salary for travelling,1/5 for his personal expenses.and rs 50 he will be depositing in the bank.what is his total salary?
Argentina had football team of 22 player of which captain is from Brazilian team and goalki from European team. For remaining player they have picked 6 from Argentinean and 14 from European. Now for a team of 11 they must have goalki and captain so out of 9 now they plan to select 3 from Argentinean and 6 from European. Find out no. Of methods available for it
Find the next series of 1,2,2,4,8,?
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
3. Given 1000 bottles of juice, one of them contains poison and tastes bitter. Spot the spoiled bottle in minimum sips?
Complete the series 2, 7, 24, 77,__ (hint: 2*12= 24, 7*11= 77, therefore 24*10= 240)
If the product of three consecutive int is 210,then sum of the two smaller ints is:
If a man buys 1 lt of milk for Rs.12 and mixes it with 20% water and sells it for Rs.15, then what is the percentage of gain?
0 Answers 3i Infotech, Amazon, Canara Bank, Mu Sigma,