Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
14 views2 pages

Two Marks

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Two Marks

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Recursion in C

Definition

Recursion in C is a process in which a function calls itself directly or indirectly until a


specific condition (called the base condition) is met.

It is mainly used to solve problems that can be broken into smaller sub-problems of the same
type (like factorial, Fibonacci series, etc.)

Syntax:

return_type function_name(parameters) {

if (base_condition) {

// Stop recursion

return value;

} else {

// Recursive call

return function_name(modified_parameters);

Example 1: Factorial using Recursion

#include <stdio.h>

// Recursive function for factorial

int factorial(int n) {

if (n == 0) // Base condition

return 1;

else

return n * factorial(n - 1); // Recursive call

int main() {

int num;

printf("Enter a number: ");


scanf("%d", &num);

printf("Factorial of %d is %d\n", num, factorial(num));

return 0;

You might also like