Answer:
let the children be x
let the dog be y
for the heads
x+y = 14 --- eqn 1
for the legs
2x + 4y = 40 ----- eqn2
since the children have 2 legs each and the dogs have 4 legs each
x + y = 14
2x+4y=40
through elimination method
multiply eqn1 by 2 and multiply eqn2 by 1
2x + 2y = 28
2x + 4y = 40 , then subtract
-2y = -12
to get y divide both sides by -2
y = 6
since in eqn 1
x+y=14
x = 14-y = 14-6 = 8
x = 8, y = 6
the children are 8 while the dogs are 6