Answer:
Ahh! What a classic: Systems of Equations!
So, if you don't know what a system of equations is, its basically two equations with two variables combined into a system.
So, let x=# of pigs
And also, Let y=# of chickens
Let's make our first equation!

This is because there are 13 animals in a barn.
So then, knowing that a pig has 4 legs and a chicken 2:

This is because there are 40 legs in total, and we multiply the variable because that's how many legs each creature has.
So, here is our system!

Through Substitution (the inputting of something instead of a variable):

Then, we input it into the next equation:

This means that there are 6 chickens, and by inputting it into the first equation:

So there you have it!
FYI there are 6 chickens and 7 pigs.
Hope this helps!
P.S. Stay Safe!