C algorithms - Factorial and Swap