0% found this document useful (0 votes)
10 views10 pages

Understanding Recursive Functions

1. A recursive function is a function that calls itself during its execution. It is used to find factorial numbers by calling itself with decreasing arguments until a base case is reached. 2. The formula for calculating factorials recursively is N=n*fact(n-1), where fact(0)=1. 3. There are different types of recursion like direct, indirect, nested, and tail recursion that make code more concise.

Uploaded by

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

Understanding Recursive Functions

1. A recursive function is a function that calls itself during its execution. It is used to find factorial numbers by calling itself with decreasing arguments until a base case is reached. 2. The formula for calculating factorials recursively is N=n*fact(n-1), where fact(0)=1. 3. There are different types of recursion like direct, indirect, nested, and tail recursion that make code more concise.

Uploaded by

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

statement of recursive

1. What is recursive function?

definition: a function which calls itself is


called recursive function. And it is technique is
known of recursion.
[Link] it is use for factorial number find out.

[Link] of factorial number find out. N=n*fact(n-1).

[Link] call from body.

[Link] case use for stopping the recursive function.

[Link] makes code smaller.

[Link] of recursive function ?


Recursive function

statements

condition
True

False
Remaining statement

stop
Source code

//factorial program using recursion


#include<stdio.h>
Int fact(int)
Void main
{ int n result;
Printf(“Enter any number:\n”)
Scanf(“%d”,&n);
Result=fact(n);
Printf(“factorial is = %d”, result);
}
Int fact(int x);
{
Int f;
If(x==1)
Return 1;
7. Find out of 5 factorial number ?

5!=5*4!
4!=4*3!
3!=3*2!
2!=2*1!
1!=1*0!
0!=1
1!=1*1=1
2!=2*1=2
3!=3*2=6
4!=4*6=24
5!=5*24=120

or

#include<stdio.h>
Int fact ()
Int sum (int n)
{
If(n==1)
Return 1
Else
Return n=sum(n-1))
5+sum(n-1)
5+4+sum(n-1)
5+4+3+sum(n-1)
5+4+3+2+sum(n-1)
5+4+3+2+1
15

Recursive variations

[Link] recursive.
[Link] recursive.
[Link] recursive.
[Link] recursive
[Link] recursive
#include<stdio.h>
Int fact (int n)
{
If(n==1)//termiting condition
Return=1
else
return n*fact(n-1).

You might also like