What is recursion? Write a "C" program that will calculate the factorial of given integer.
|NU Year||Set: 2.(d) Marks: 6 Year: 2013|
Recursion is the process of repeating items in a self-similar way. In programming languages, if a program allows you to call a function inside the same function, then it is called a recursive call of the function.
int i, fact = 1, num;
printf("Enter the number \n");
if (num <= 0)
fact = 1;
for (i = 1; i <= num; i++)
fact = fact * i;
printf("Factorial of %d = %5d\n", num, fact);