Senin, 19 Oktober 2015

How Recursion Work In C Programming Language

How Recursion Work In C

 
     Recursion is a process to repeat things or items in similar way. when we want to make a recursion program, we can use function. recursion can be use to calculate and solve mathematical problems, like factorial problem, fibonacci, multiplication, matrix multiplication, etc.

this is the concept how to use recursion using function :
void recursion ()
{
 recursion bla bla bla;  // this function will call itself as recursion
int main ()
{
recursion  bla bla bla; // you may set off the recursion here
return 0;
}

that is just a simple concept how to use recursion. to continue, here is a simple example to use recursion in sum :
#include <stdio.h>

int i = 1;

void function (int sum)
{
sum = sum + i;
i++;

if (i<=9)
{
function (sum);
}
else
{
printf(" the result of sum : %d \n", sum);
}
return;
}

int main ()
{
int sum = 0;
function (sum);
return 0;
}

so here is the explanation about the simple example :
you given numbers from 0 until 9. and you must sum these number with this way:
0 + 1 = 1
1 + 2 = 3
3 + 3 = 6
6 + 4 = 10
10 + 5 = 15
15 + 6 = 21
21 + 7 = 28
28 + 8 = 36
36 + 9 = 45

so, that's about how recursion work. i hope you can understand, because my skill is not really high. i also still a little don't understand about recursion. hope you enjoy and thank you :)