|
|
Recursion: In mathematics and computer science, is a method of defining functions in which the function being defined is applied within its own definition; specifically it is defining an infinite statement using finite component. The term is also used more generally to describe a process of repeating objects in a self-similar way. For instance, when the surfaces of two mirrors are exactly parallel with each other the nested images that occur are a form of infinite recursion.
Factorial: In mathematics, the factorial of a positive integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example,
6! = 1 x 2 x 3 x 4 x 5 x 6 = 720
Source: Wikipedia
This Program will output Factorial of a number with Recursion Function
Code:
#include<stdio.h>
#include<conio.h>
double factorial(int n);
void main()
{
int n;
double Result;
clrscr();
printf("Enter Number (n): ");
scanf("%d", &n);
Result = factorial(n);
printf("Factorial of %d is %.0lf", n, Result);
getch();
}
double factorial(int n)
{
if (n == 0)
{
return 1;
}
else
{
return n * factorial(n-1);
}
}
|
IP Logged
|
I am a Lazy Coder. |