Write a Program to find the factorial of a number using function

#include<stdio.h>
#include<conio.h>
void main()
{
     long factorial(int);
     int n;
     long fact;
     clrscr();
     printf("\nEnter an integer\n");
     scanf("%d",&n);
     fact=factorial(n);
     printf("\nFactorial of %d=%ld",n,fact);
     getch();
     return 0;
}
long factorial(int n)
{
   long f=1;
   int i;
   if(n==0)
     return 1;
     for(i=1;i<=n;i++)
     f=f*i;
     return f;
}

No comments:

Post a Comment