Question 698414
You have to make two equations and solve them together.
Let the number of chickens be called c and let the number of pigs be p.
there are 13 animals in the barn so 
p + c = 13 this is equation 1.
Since pigs have 4 legs the number of legs that the pigs have altogether is 4p and similarly chickens only have 2 legs so the number of their legs will be 2c.
so 2c + 4p = 40 this is equation 2
using equation 1 we can see that c = 13 - p
putting this value into equation 2 and solving
2X(13-p) + 4p = 40
26-2p+4p = 40
2p = 14
p = 7 there are 7 pigs
hence there are 6 chickens