understanding recursive functions
Hi, this is my first post here.
I'm having trouble understanding the logic of recursive functions. I'm doing a self study on C programming for linux and I'm having problems understanding how recursive functions work.
like I have no idea what's going on here, and the book doesn't further explain recursive functions to enlighten me: What's going on here?
Code:
/* Takes the value 3 to the power of another number */
#include <stdio.h>
int three_powered (int power);
int main(void)
{
int a = 4, b = 19;
printf("3 to the power of %d is %d\n", a, three_powered(a));
printf("3 to the power of %d is %d\n", b, three_powered(b));
return 0;
}
int three_powered (int power)
{
if (power < 1)
return 1;
else
return 3 * three_powered (power -1);
}
I'm just not understanding it. Any help is appreciated. I really want to understand this.
Psuedo code might help me to understand it.