♦ C Recursive Function
♣ About C Recursive Function
Functions can be invoked internally from the same Function, this paradigm is known as Recursion.This paradigm of programming is helpful when there some type of sequencing pattern noticed in subsequent function calls.
♣ C Recursive Function Syntax
Below is the representation of C Recursive Functions Syntax.Basic Syntax
returnType functionName(inputArgument1, inputArgument2, ...){ // Body of Function functionName(internalInputArgument1, internalInputArgument2, ...); return result; }
Syntax Explanation:
returnType: the data type of return value which produced post function processing
inputArgument1, inputArgument2, ... : Input parameters which will be used inside function body
// Body of Function: all of the code processing goes here
internalInputArgument1, internalInputArgument2, ... : the modified parameters which are passed to internal funtion
result: calculated result is returned from this variable
inputArgument1, inputArgument2, ... : Input parameters which will be used inside function body
// Body of Function: all of the code processing goes here
internalInputArgument1, internalInputArgument2, ... : the modified parameters which are passed to internal funtion
result: calculated result is returned from this variable
♣ Example1: Factorial with C Function Recursion
In this example, factorial of a number will be calculated by recursive function calling. Example
Input:
Output:
♣ Example2: Sum of Natural Numbers with C function Recursion
In this example, sum up n natural numbers will be calculated by recusive function calling. Example
Input:
Output: