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 |
2, 6, 12, 20, 30, ___, 56
14 Answers EA Electronic Arts,
If the vertex (5,7) is placed in the memory. First vertex (1,1) ?s address is 1245 and then address of (5,7) is ----------
0 Answers Accenture, BSNL, TCS,
sir i need placement paper of assurgent company
In China, Mao-Tse-Tung was responsible for organizing its people and taking China into success path. It evolved into a great economic power by improved industrial and economical statistics. China prospered in those years, but _________________
Given a collection of points P in the plane, a 1-set is a point in P that can be separated from the rest by a line; i.e. the point lies on one side of the line while the others lie on the other side. The number of 1-sets of P is denoted by n1(P). The maximum value of n1(P) over all configurations P of 19 points in the plane is 18 9 3
If a car starts from A towards B with some velocity due to some problem in the engine after travelling 30km.If the car goes with 4/5 th of its actuval velocity the car reaches B 45min later to the actual time. If the car engine fails ofter travelling 45km, the car reaches the destination B 36min late to the actual time , what is the initial velocity of car and what is the distance between A and B in km ans) 20 &
What is the difference between monkey testing,gorilla testing and chimpazee testing.
at a certain ice cream parlour customer can choose among three different ice cream flavour and can choose either a sugar cone or a waffle cone. considerig both ice cream flavour and cone type how many distinct tripple scoop cone with three different ice cream flavour and available.
84 mens complete the work in 17 day. how much time 119 person take to complete the work.
I HAVE APPLIED RRB EXAM. SO IWANT TO MODEL OUESTION PAPERS (DEGREE)
If a and b are positive integers, is a + 4b odd? 1) b is even. 2) a is odd. a) if statement (1) ALONE is sufficient, but statement (2) alone is not sufficient to answer the question. b) if statement (2) ALONE is sufficient, but statement (1) alone is not sufficient to answer the question. c) if BOTH statements (1) and (2) TOGETHER are sufficient to answer the question asked, but NEITHER statement ALONE is sufficient. d) if EACH statement ALONE is sufficient to answer the question asked. e) if statements (1) and (2) TOGETHER are NOT sufficient to answer the question asked, and additional data specific to the problem are needed.
Input an array and then print the repeating characters?? Example: Input:1,3,23,11,44,3,23,2,3. Output:3,23 plz help me.... i want a code of it. In C language.