Filled Under: ,

C Program to Find Factorial of a Number Using Recursion

C Program to Find Factorial of a Number Using Recursion

C program to find factorial of a number using recursion


In this program, I have discussed about the C program to find factorial of a number using recursion.

The formula which we will use is stated below.-
(n)!/(r!*(n-r)!)

#include<stdio.h>
int fact(int);
int main()
{ int a,b,c,n,r,res;
printf("Enter the value of n and r :\n");
scanf("%d%d",&n,&r);
a=fact(n);
b=fact(r);
c=fact(n-r);
res=a/(b*c);
printf("The value is %d \n",res);
}
int fact(int s)
{ int k=1,i;
for(i=1;i<=s;i++)
{ k*=i;
}
return k;
}


Just copy and paste the program in your desired compiler (Dev C++ is more preferable) and run it.

Enjoy programming in C.


0 comments:

Post a Comment

 

Copyright 2020 Programming in C All Right Reserved