‘C’ to calculate factorial of a number using recursion.
C File =>
/* Write a recursive function in ‘C’ to calculate factorial of a number. Use
this function in main. */
#include<stdio.h>
int main()
{
int num;
// defining recursive function
int fact(int n)
{
if(n==1 || n==0)
return 1;
else
return(n*fact(n-1));
}
printf("\n Enter number : ");
scanf("%d",&num);
printf("\n Factorial of %d is %d",num,fact(num));
return 0;
}
Comments
Post a Comment
Please do not enter any spam link in message.