c + p = 13
2c + 4p = 40
We can do this a few ways, but let's solve the first for c and substitute.
c = 13 - p
Now, since c and 13 - p are equal, we can substitute one for the other.
2(13 - p) + 4p = 40
26 - 2p + 4p = 40
2p = 14
p = 7
c = 13 - 7 = 6
There are 7 pigs and 6 chickens.