Search This Blog

C progam for finding factorial of a number using function

//coded by Z
#include<stdio.h>
int fact(int n);
void main()
{
 int n,f;
 clrscr();
 printf("\n Enter the value of n=");
 scanf("%d",&n);
 f=fact(n);
 printf("\nfactorial of %d is %d",n,f);
 getch();
}
 int fact(int n)
 {
  int f;
  if(n==0)
  return(1);
 else
   f=n*fact(n-1);
   return(f);
 }

No comments:

Post a Comment