C Program to find factorial of a number using recursion.

/*  Write a C Program to find factorial of a number using recursion.  */
===================================================
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf(“enter number: ”);
scanf(“%d”,&n);
if(n<0)
printf(“invalid number”);
else
printf(“%d!=%d”,n,fact(n));
getch();
}
int fact(int x)
{
if(x==0)
return 1;
else
return(x*fact(x-1));
}

Output:
=======
enter number: 5
5!=120

No comments: