x is the number of ducks
y is the number of goats
The total number of animals is 12, then
x + y = 12 (1)
Since each duck has 2 legs
Since each goat has 4 legs, then
The total number of the legs is 2x + 4y
Since the total number of legs is 34, then
2x + 4y = 34 (2)
Now we have a system of equations to solve it
Multiply equation (1) by -2 to make the coefficients of x equal in value but opposite in signs to eliminate x
-2(x) + -2(y) = -2(12)
-2x - 2y = -24 (3)
Add equations (2) and (3)
(2x + -2x) + (4y + -2y) = (34 + -24)
0 + 2y = 10
2y = 10
Divide both sides by 2
y = 5
Substitute the value of y in equation (1) to find x
x + 5 = 12
Subtract 5 from both sides
x + 5 - 5 = 12 - 5
x = 7
There are 7 ducks and 5 goats in the farmhouse
7 x 2 = 14 and 5 x 4 = 20, then
The sum of their legs = 14 + 20 = 34