You are on page 1of 9

UIC Department

Submitted By :- Pawan Kumar, Garvit Bhatia


UID :- 19BCA1277, 19BCA1269
COMPUTER PROGRAMMING
PRESENTATION

On Topic
Recursion Function
FUNCTION
A function is a set of statements that take
inputs, do some specific computation and
produces output.
The idea is to put some commonly or
repeatedly done task together and make a
function so that instead of writing the
same code again and again for different
inputs, we can call the function.
TYPES OF FUNCTIONS
a) Standard library functions
 The standard library functions are built-in
functions in C programming.
 These functions are defined in header files. For
example,
 The printf() is a standard library function to send
formatted output to the screen (display output on
the screen). This function is defined in
the stdio.h header file.
Hence, to use the printf() function, we need to
include the stdio.h header file using #include
<stdio.h>.
 The sqrt() function calculates the square root of a
number. The function is defined in
the math.h header file.
b)User-defined function
 You can also create functions as per your need. Such
functions created by the user are known as user-
defined functions.
 A user-defined function is easier to understand and is
more flexible than a standard library function.
RECURSION FUNCTION
Recursion is a programming technique that allows the
programmer to express operations in terms of themselves.
In C, this takes the form of a function that calls itself. A
useful way to think of recursive functions is to imagine
them as a process being performed where one of the
instructions is to "repeat the process". This makes it sound
very similar to a loop because it repeats the same code, and
in some ways it is similar to looping. On the other hand,
recursion makes it easier to express ideas in which the
result of the recursive call is necessary to complete the
task. Of course, it must be possible for the "process" to
sometimes be completed without the recursive call. One
simple example is the idea of building a wall that is ten feet
high; if I want to build a ten foot high wall, then I will first
build a 9 foot high wall, and then add an extra foot of
bricks. Conceptually, this is like saying the "build wall"
function takes a height and if that height is greater than
one, first calls itself to build a lower wall, and then adds
one a foot of bricks
SYNTAX

void recursion()
{
recursion(); /* function calls itself */
}
int main()
{
recursion();
}
EXAMPLE
 The following example calculates the factorial of a given number using a recursive
function

#include <stdio.h>

unsigned long long int factorial(unsigned int i) {

if(i <= 1) {
return 1;
}
return i * factorial(i - 1);
}

int main() {
int i = 12;
printf("Factorial of %d is %d\n", i, factorial(i));
return 0;
}
Thank You

You might also like