There are 13 animals in the barn. some are chickens and some are pigs. there are 40 legs in all. How many of each animal are there?

Chickens have 2 legs, pigs have 4 legs. Let c be the number of chickens and p be the number of pigs. Set up our givens:
(1) c + p = 13
(2) 2c + 4p = 40

Rearrange (1) to solve for c by subtracting p from both sides:
(3) c = 13 - p