Factorail Using RECURSSION.

//Factorial Using Recurssion.

#include<stdio.h>
long factorial(int);
int main()
{
 int n;long f; printf("enter no\n");scanf("%d",&n);
 if(n<0)
 printf("negative no is not allowed\n");
 else
 {
  f=factorial(n);
  printf("%d!=%ld",n,f);
 }
}
long factorial(int n)
{
 if(n==1)
 return 1;
 else{
  return(n*factorial(n-1));
 }
}

No comments:

Post a Comment