Recursive function.
#1

So I have this(which is a code written from e pseudocode from our last class) C little recursive function.

pawn Code:
int power3(int x, int n);
int power3(int x, int n)
{
    int p;
    if(n == 2)
        return (x * x);
    else
        p = power3(x, (n/2));
    return (p * p);
}
Now to check it in main()
pawn Code:
printf("%d",  power3(2, 24));
It never calls power3 again, checked it using printf's before and after, it repeats endlessly the before printf.
pawn Code:
else
{
        printf("B. %d", p);
        p = power3(x, (n/2));
        printf("A. %d", p);
}
And it crashes my console and stops working.


Ani ideas? Also, I would like to ask you guys for a coding forum, so I can stop bothering you guys
Reply


Messages In This Thread
Recursive function. - by Zh3r0 - 04.12.2014, 10:49
Re: Recursive function. - by Smithy - 04.12.2014, 11:21
Re: Recursive function. - by Zh3r0 - 04.12.2014, 11:33
Re: Recursive function. - by KingHual - 04.12.2014, 11:50
Re: Recursive function. - by Zh3r0 - 05.12.2014, 05:19
Re: Recursive function. - by DaTa[X] - 05.12.2014, 05:29
Re: Recursive function. - by Zh3r0 - 05.12.2014, 06:34
Re: Recursive function. - by Vince - 05.12.2014, 06:43
Re: Recursive function. - by Zh3r0 - 05.12.2014, 07:23
Re: Recursive function. - by Smithy - 05.12.2014, 08:14

Forum Jump:


Users browsing this thread: 1 Guest(s)