Thursday

Write a program to calculate the factorial of a given number using recursive function.

#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
 int n,a;
 clrscr();
 printf("\nEnter any number: ");
 scanf("%d",&n);
 a=fact(n);
 printf("\n factorial= %d",a);
 getch();
 }

int fact(int n)
{
 if(n<=1)
 return 1;
 else
 return(n*fact(n-1));
}

No comments:

Post a Comment

Rahul-Notes