SlideShare a Scribd company logo
1 of 8
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 (20)

Strings in C
Strings in CStrings in C
Strings in C
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Array in c
Array in cArray in c
Array in c
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
 
Structure of C++ - R.D.Sivakumar
Structure of C++ - R.D.SivakumarStructure of C++ - R.D.Sivakumar
Structure of C++ - R.D.Sivakumar
 
Call by value
Call by valueCall by value
Call by value
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Type Conversion, Precedence and Associativity
Type Conversion, Precedence and AssociativityType Conversion, Precedence and Associativity
Type Conversion, Precedence and Associativity
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
arrays and pointers
arrays and pointersarrays and pointers
arrays and pointers
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
C functions
C functionsC functions
C functions
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Call by value or call by reference in C++
Call by value or call by reference in C++Call by value or call by reference in C++
Call by value or call by reference in C++
 

Similar to Recursive Function

Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxKhurramKhan173
 
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 ShahzadFaisal Shehzad
 
Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming languageVasavi College of Engg
 
Monolithic and Procedural Programming
Monolithic and Procedural ProgrammingMonolithic and Procedural Programming
Monolithic and Procedural ProgrammingDeepam Aggarwal
 
Algorithm and Data Structure - Modular Programming
Algorithm and Data Structure - Modular ProgrammingAlgorithm and Data Structure - Modular Programming
Algorithm and Data Structure - Modular ProgrammingAndiNurkholis1
 
lecture-c-corr-effkkkkkkkkkkkkkp (1).ppt
lecture-c-corr-effkkkkkkkkkkkkkp (1).pptlecture-c-corr-effkkkkkkkkkkkkkp (1).ppt
lecture-c-corr-effkkkkkkkkkkkkkp (1).pptZeeshanAli593762
 
chapter-8-function-overloading.pdf
chapter-8-function-overloading.pdfchapter-8-function-overloading.pdf
chapter-8-function-overloading.pdfstudy material
 
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 | FabMinds
 
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 topssameermhr345
 
Functions in c++
Functions in c++Functions in c++
Functions in c++Maaz Hasan
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptxmiki304759
 
NIE2206 Electronic LogbookNamexxxStudent IDUxxxTe.docx
NIE2206 Electronic LogbookNamexxxStudent IDUxxxTe.docxNIE2206 Electronic LogbookNamexxxStudent IDUxxxTe.docx
NIE2206 Electronic LogbookNamexxxStudent IDUxxxTe.docxcurwenmichaela
 
10 implementing subprograms
10 implementing subprograms10 implementing subprograms
10 implementing subprogramsMunawar Ahmed
 

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

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 "Harsh Pathak
 
Control Engineering "Force Voltage Analogy"
Control Engineering "Force Voltage Analogy"Control Engineering "Force Voltage Analogy"
Control Engineering "Force Voltage Analogy"Harsh Pathak
 
:Heat Transfer "Lumped Parameter Analysis "
:Heat Transfer "Lumped Parameter Analysis ":Heat Transfer "Lumped Parameter Analysis "
:Heat Transfer "Lumped Parameter Analysis "Harsh Pathak
 
Fluid Power Engineering "Hydraulic Accumulator"
Fluid Power Engineering "Hydraulic Accumulator"Fluid Power Engineering "Hydraulic Accumulator"
Fluid Power Engineering "Hydraulic Accumulator"Harsh Pathak
 
Types of Dynamometers
Types of DynamometersTypes of Dynamometers
Types of DynamometersHarsh Pathak
 
Taylor and Maclaurin Series
Taylor and Maclaurin SeriesTaylor and Maclaurin Series
Taylor and Maclaurin SeriesHarsh Pathak
 
Contruction material cement
Contruction material cementContruction material cement
Contruction material cementHarsh Pathak
 
Demostrate Trust Behaviour-CPD
Demostrate Trust Behaviour-CPDDemostrate Trust Behaviour-CPD
Demostrate Trust Behaviour-CPDHarsh 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

OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17Celine George
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningMarc Dusseiller Dusjagr
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111GangaMaiya1
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17Celine George
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 

Recently uploaded (20)

OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 

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