Factorial



#include "stdio.h"
int j;
double factorial (int v)
{
   double ans=1;
   int i;
   for(i=2;i<=v;i++)
   ans*=i;
   return ans;
}
int main (void)
{
    int val;
    printf("Enter a non-negative number:\n");
    scanf("%d",&val);
    printf("factorial of %d is %lf\n", val, factorial(val));
    system("pause");
    return 0;
}

0 comments:

Post a Comment