# Thread: Can anybody show me why this works??

1. ## Can anybody show me why this works??

I found this recursive function code in a C book. I do not understand why it works. It seems to me that there is no variable in the function the keep up with the results, yet it works perfectly! Just curious.

Thanks to anyone who can trace this program and show me what it is doing that I cannot see.

tzuch

Code:
```#include <stdio.h>

int three_powered(int power);

main(void)
{
int a=0, fin;

puts("Enter an exponent:  ");
scanf("%d", &a);

printf("\n3 to the power of %d is %d",a,three_powered(a) );

puts("\n\nEnter a digit...");
scanf("%d", &fin);

return 0;

}

int three_powered(int power)
{
if(power<1)
{
return 1;
}

else
{
return(3*three_powered(power-1));
}
}```

Code:
```#include <stdio.h>

int three_powered(int power);

int main(void)
{
int a=0, fin;

puts("Enter an exponent:  ");
scanf("&#37;d", &a);

printf("\n3 to the power of %d is %d",a,three_powered(a) );

puts("\n\nEnter a digit...");
scanf("%d", &fin);

return 0;

}

int three_powered(int power)
{
if(power<1)
{
printf ("3^0 == 1\n");
return 1;
}
else
{
int res  = 3*three_powered(power-1);
printf ("3^%d == %d\n", power, res);
return(res);
}
}```

3. thank you very much vart. I should have done that but I'm fairly new at this.

tzuch