Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 10

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.
2.Mainly it is use for factorial number find out.

3.Formulla of factorial number find out. N=n*fact(n-1).

4.It call from body.

5.Base case use for stopping the recursive function.

6.Recursion makes code smaller.

7.Flowchart 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

1.Derect recursive.
2.Inderect recursive.
3.Nested recursive.
4.Excessive recursive
5.Tail 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