Thursday, April 7, 2016

Program Calculate Factorial of a given number using Recursion.

#include<stdio.h>
#include<conio.h>
int fact(int n)
{
if(n==1)
return 1;
else
return n*fact(n-1);
}
void main()
{
int n,ans;
clrscr();
printf("Enter a value:");
scanf("%d",&n);
ans=fact(n);
printf("fact of %d is %d",n,ans);
getch();
}

No comments:

Post a Comment