Home > Back-end >  The problem solving with c language
The problem solving with c language

Time:11-28

There is a group of chicken and a group of rabbits, two kinds of animals have the same number, the total number of two kinds of animal's feet are three digits, and the two three digits of the six Numbers are respectively 0,1,2,3,4,5, programming and how much is the chicken and rabbit only count? What is the number of their feet?

O, help, save the children

CodePudding user response:

Advice from the Internet search, so that the title of the very popular, the person also many,

CodePudding user response:

Fyi:
 # include & lt; stdio.h> 

Int main (void)
{
Int num, result, foot1 foot2;

For (num=50; Num & lt; 250; Num++)
{
Foot1 num=2 *;
Foot2 num=4 *;

Result=0;
The result |=(1 & lt; <(10) foot1 %);
The result |=(1 & lt; <(100/10) foot1 %);
The result |=(1 & lt; <(foot1/100));

The result |=(1 & lt; <(10) foot2 %);
The result |=(1 & lt; <(100/10) foot2 %);
The result |=(1 & lt; <(foot2/100));

If (result==63)
{
Printf (" chicken number: \ t % d feet count: \ n \ t % d ", num, 2 * num);
Printf (" rabbit number: \ t % d feet count: \ n \ t % d ", num, 4 * num);
}
}

return 0;
}

Results:
 E: \ Workspace> TCC - run the demo. C 
Chicken number: 76 feet number: 152
Rabbit: 76 feet number: 304

CodePudding user response:

refer to the second floor ctrigger response:
are for reference only:
 # include & lt; stdio.h> 

Int main (void)
{
Int num, result, foot1 foot2;

For (num=50; Num & lt; 250; Num++)
{
Foot1 num=2 *;
Foot2 num=4 *;

Result=0;
The result |=(1 & lt; <(10) foot1 %);
The result |=(1 & lt; <(100/10) foot1 %);
The result |=(1 & lt; <(foot1/100));

The result |=(1 & lt; <(10) foot2 %);
The result |=(1 & lt; <(100/10) foot2 %);
The result |=(1 & lt; <(foot2/100));

If (result==63)
{
Printf (" chicken number: \ t % d feet count: \ n \ t % d ", num, 2 * num);
Printf (" rabbit number: \ t % d feet count: \ n \ t % d ", num, 4 * num);
}
}

return 0;
}

Results:
 E: \ Workspace> TCC - run the demo. C 
Chicken number: 76 feet number: 152
Rabbit: 76 feet number: 304

Oh thank you thank you thank you!!!

CodePudding user response:

refer to the second floor ctrigger response:
are for reference only:
 # include & lt; stdio.h> 

Int main (void)
{
Int num, result, foot1 foot2;

For (num=50; Num & lt; 250; Num++)
{
Foot1 num=2 *;
Foot2 num=4 *;

Result=0;
The result |=(1 & lt; <(10) foot1 %);
The result |=(1 & lt; <(100/10) foot1 %);
The result |=(1 & lt; <(foot1/100));

The result |=(1 & lt; <(10) foot2 %);
The result |=(1 & lt; <(100/10) foot2 %);
The result |=(1 & lt; <(foot2/100));

If (result==63)
{
Printf (" chicken number: \ t % d feet count: \ n \ t % d ", num, 2 * num);
Printf (" rabbit number: \ t % d feet count: \ n \ t % d ", num, 4 * num);
}
}

return 0;
}

Results:
 E: \ Workspace> TCC - run the demo. C 
Chicken number: 76 feet number: 152
Rabbit: 76 feet number: 304

There is a place I still don't understand, why there is the (result==63)?

CodePudding user response:

The
reference 4 floor Milo Tuan response:
there is a place I still don't understand, why there is the (result==63)?

Bit operations, the result is 63, or 0 x3f,
  • Related