//Why are recursions?
//We can solve difficult long iteratively can be
solved simply recursively.
// there are some problems which suited to be
solved recursively.
// eg. tower of Hanoi, Fibonacci series,
factorial finding.
#include <stdio.h>
int factorial(int number)
{
if(number == 1 || number == 0)
{
return 1;
}
else{
return (number * factorial(number-1));
}
}
int main ()
{
int num;
printf ("Enter the number which factorial value you want: ");
scanf ("%d", &num);
printf ("The factorial value of %d is %d.",num, factorial(num));
return 0;
}
output:_
Enter the number which factorial value you want: 7
The factorial value of 7 is 5040.
No comments:
Post a Comment
here we are to help you.you can watch videos and get information about :- (1) scientific facts (2) education (3) gaming (4) music (5) lyrics (6) cartoons and many more.So keep watching keep learning, thank you.