1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#include <stdio.h> #include <math.h> #include "factorial.h" float sfactorials(float in) { int i,n; long long int fact=1; n=(int)in; if (n < 0) printf("Error! Factorial of a negative number doesn't exist."); else if(n>170) printf("Inf"); else { for(i=1; i<=n; i++) { fact *= i; } } return fact; }