A farmer has only pigs and chickens. When she stands on her porch and surveys her stock, she sees 22 heads and 52 legs. How many chickens does she have and how many pigs?

legs = 4 p + 2 c = 52

p+c = 22 so p = 22-c

4(22-c) + 2 c = 52

88 - 2 c = 52

2 c = 36

c = 18
then p = 4