SlideShare a Scribd company logo
Prepared by-
Harsh Pathak
Guided by – Prof. Rohit Singh
Gandhinagar Institute of Technology
SUBJECT-CPU (2110003)
Recursive Function
Contents
1 What is Recursive Function?
2 Advantage and Disadvantage
3 Program
4 Output
Recursive Function
2
What is Recursive Function?
When a called function in turns calls another
function a process of ‘chaining’ occurs. Recursion
is a simple special case of this process, where a
function call itself.
Recursive Function
3
A very simple example of recursion is presented
below:
main( )
{
printf(“This is an example of recursion n”);
main( );
}
When executed this program will produce an output
:
This is an example of recursion
This is an example of recursion
This is an example of recursion
The Execution will continue indefinitely.
Recursive Function
4
Advantage and Disadvantage
• Advantages
*Easy solution for recursively defined problems.
*Complex programs can be easily written in less
code.
• Disadvantage
*Recursive code is difficult to understand and
debug
*Terminating condition is must, otherwise it will go
in infinite loop.
*Execution speed decreases because of function
call and return activity many times.Recursive Function
5
PROGRAM
#include<stidio.h>
#include <conio.h>
long int fact (int n); /*prototype of function*/
int main()
{ int m;
long int ans; /*long in store large number*/
clrscr();
printf("Enter the number:n);
scanf("%d", &m);
ans=fact(m); /*call fuction fact() with call by value*/
printf("Factorial of %d using function = %ld", m, ans);
}
long int fact(int n) /*function body here*/
{ if (n == 1|| n==0)
return 1;
else
return n*fact(n-1); /*recursion here. fact() calls fact()*/
}
6
OUTPUT
Give the number
6
Factorial of using function=720
Give the number
0
Factorial of using function=0
Cox / RixnerArrays and Pointers7
8

More Related Content

What's hot

What's hot (20)

user defined function
user defined functionuser defined function
user defined function
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
 
C tokens
C tokensC tokens
C tokens
 
Loops in C Programming Language
Loops in C Programming LanguageLoops in C Programming Language
Loops in C Programming Language
 
Templates in c++
Templates in c++Templates in c++
Templates in c++
 
Constructor overloading & method overloading
Constructor overloading & method overloadingConstructor overloading & method overloading
Constructor overloading & method overloading
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
 
Structure in C
Structure in CStructure in C
Structure in C
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Two dimensional arrays
Two dimensional arraysTwo dimensional arrays
Two dimensional arrays
 
Strings in C
Strings in CStrings in C
Strings in C
 
String in c programming
String in c programmingString in c programming
String in c programming
 
Python functions
Python functionsPython functions
Python functions
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
Operators in python
Operators in pythonOperators in python
Operators in python
 

Similar to Recursive Function

Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming language
Vasavi College of Engg
 
Funtions of c programming. the functions of c helps to clarify all the tops
Funtions of c programming. the functions of c helps to clarify all the topsFuntions of c programming. the functions of c helps to clarify all the tops
Funtions of c programming. the functions of c helps to clarify all the tops
sameermhr345
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
miki304759
 
NIE2206 Electronic LogbookNamexxxStudent IDUxxxTe.docx
NIE2206 Electronic LogbookNamexxxStudent IDUxxxTe.docxNIE2206 Electronic LogbookNamexxxStudent IDUxxxTe.docx
NIE2206 Electronic LogbookNamexxxStudent IDUxxxTe.docx
curwenmichaela
 

Similar to Recursive Function (20)

Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptx
 
Function overloading ppt
Function overloading pptFunction overloading ppt
Function overloading ppt
 
Python recursion
Python recursionPython recursion
Python recursion
 
Recursion in Python.pdf
Recursion in Python.pdfRecursion in Python.pdf
Recursion in Python.pdf
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
Function Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
Function Overloading,Inline Function and Recursion in C++ By Faisal ShahzadFunction Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
Function Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
 
Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming language
 
Monolithic and Procedural Programming
Monolithic and Procedural ProgrammingMonolithic and Procedural Programming
Monolithic and Procedural Programming
 
Zend Framework 2 - PHPUnit
Zend Framework 2 - PHPUnitZend Framework 2 - PHPUnit
Zend Framework 2 - PHPUnit
 
Algorithm and Data Structure - Modular Programming
Algorithm and Data Structure - Modular ProgrammingAlgorithm and Data Structure - Modular Programming
Algorithm and Data Structure - Modular Programming
 
Plc part 3
Plc  part 3Plc  part 3
Plc part 3
 
lecture-c-corr-effkkkkkkkkkkkkkp (1).ppt
lecture-c-corr-effkkkkkkkkkkkkkp (1).pptlecture-c-corr-effkkkkkkkkkkkkkp (1).ppt
lecture-c-corr-effkkkkkkkkkkkkkp (1).ppt
 
chapter-8-function-overloading.pdf
chapter-8-function-overloading.pdfchapter-8-function-overloading.pdf
chapter-8-function-overloading.pdf
 
Python Programming | JNTUA | UNIT 2 | Fruitful Functions |
Python Programming | JNTUA | UNIT 2 | Fruitful Functions | Python Programming | JNTUA | UNIT 2 | Fruitful Functions |
Python Programming | JNTUA | UNIT 2 | Fruitful Functions |
 
Funtions of c programming. the functions of c helps to clarify all the tops
Funtions of c programming. the functions of c helps to clarify all the topsFuntions of c programming. the functions of c helps to clarify all the tops
Funtions of c programming. the functions of c helps to clarify all the tops
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
 
NIE2206 Electronic LogbookNamexxxStudent IDUxxxTe.docx
NIE2206 Electronic LogbookNamexxxStudent IDUxxxTe.docxNIE2206 Electronic LogbookNamexxxStudent IDUxxxTe.docx
NIE2206 Electronic LogbookNamexxxStudent IDUxxxTe.docx
 
10 implementing subprograms
10 implementing subprograms10 implementing subprograms
10 implementing subprograms
 
Procedural programming
Procedural programmingProcedural programming
Procedural programming
 

More from Harsh Pathak

More from Harsh Pathak (11)

Design of Machine Element "Thick Wall Pressure Vessel "
Design of Machine Element "Thick Wall Pressure Vessel "Design of Machine Element "Thick Wall Pressure Vessel "
Design of Machine Element "Thick Wall Pressure Vessel "
 
Control Engineering "Force Voltage Analogy"
Control Engineering "Force Voltage Analogy"Control Engineering "Force Voltage Analogy"
Control Engineering "Force Voltage Analogy"
 
:Heat Transfer "Lumped Parameter Analysis "
:Heat Transfer "Lumped Parameter Analysis ":Heat Transfer "Lumped Parameter Analysis "
:Heat Transfer "Lumped Parameter Analysis "
 
Fluid Power Engineering "Hydraulic Accumulator"
Fluid Power Engineering "Hydraulic Accumulator"Fluid Power Engineering "Hydraulic Accumulator"
Fluid Power Engineering "Hydraulic Accumulator"
 
Types of Dynamometers
Types of DynamometersTypes of Dynamometers
Types of Dynamometers
 
160120119028dme
160120119028dme160120119028dme
160120119028dme
 
Taylor and Maclaurin Series
Taylor and Maclaurin SeriesTaylor and Maclaurin Series
Taylor and Maclaurin Series
 
Contruction material cement
Contruction material cementContruction material cement
Contruction material cement
 
Demostrate Trust Behaviour-CPD
Demostrate Trust Behaviour-CPDDemostrate Trust Behaviour-CPD
Demostrate Trust Behaviour-CPD
 
Ic engine
Ic engineIc engine
Ic engine
 
Noise pollution
Noise pollutionNoise pollution
Noise pollution
 

Recently uploaded

Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 

Recently uploaded (20)

Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptBasic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matrices
 
Gyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptxGyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptx
 
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
Operations Management - Book1.p  - Dr. Abdulfatah A. SalemOperations Management - Book1.p  - Dr. Abdulfatah A. Salem
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
B.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdfB.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdf
 
The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resources
 
The impact of social media on mental health and well-being has been a topic o...
The impact of social media on mental health and well-being has been a topic o...The impact of social media on mental health and well-being has been a topic o...
The impact of social media on mental health and well-being has been a topic o...
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
 

Recursive Function

  • 1. Prepared by- Harsh Pathak Guided by – Prof. Rohit Singh Gandhinagar Institute of Technology SUBJECT-CPU (2110003) Recursive Function
  • 2. Contents 1 What is Recursive Function? 2 Advantage and Disadvantage 3 Program 4 Output Recursive Function 2
  • 3. What is Recursive Function? When a called function in turns calls another function a process of ‘chaining’ occurs. Recursion is a simple special case of this process, where a function call itself. Recursive Function 3
  • 4. A very simple example of recursion is presented below: main( ) { printf(“This is an example of recursion n”); main( ); } When executed this program will produce an output : This is an example of recursion This is an example of recursion This is an example of recursion The Execution will continue indefinitely. Recursive Function 4
  • 5. Advantage and Disadvantage • Advantages *Easy solution for recursively defined problems. *Complex programs can be easily written in less code. • Disadvantage *Recursive code is difficult to understand and debug *Terminating condition is must, otherwise it will go in infinite loop. *Execution speed decreases because of function call and return activity many times.Recursive Function 5
  • 6. PROGRAM #include<stidio.h> #include <conio.h> long int fact (int n); /*prototype of function*/ int main() { int m; long int ans; /*long in store large number*/ clrscr(); printf("Enter the number:n); scanf("%d", &m); ans=fact(m); /*call fuction fact() with call by value*/ printf("Factorial of %d using function = %ld", m, ans); } long int fact(int n) /*function body here*/ { if (n == 1|| n==0) return 1; else return n*fact(n-1); /*recursion here. fact() calls fact()*/ } 6
  • 7. OUTPUT Give the number 6 Factorial of using function=720 Give the number 0 Factorial of using function=0 Cox / RixnerArrays and Pointers7
  • 8. 8