[Solved] Converting an iterative algorithm to a recursive one [closed]


This is almost the same as BLUEPIXY‘s answer since I believe it’s the straight forward solution, but since you are confused by the function pointer, I removed that.

#include <stdio.h>
#include <stdlib.h>

void
printValue()
{
    static unsigned int y;
    printf("%d\n", y);
    y += 1;
}

void
recursiveFunction(int counter)
{
    printValue();
    if (--counter == 0)
        return;
    recursiveFunction(counter);
}

int
main()
{
    recursiveFunction(100);
    return 0;
}

Or may be you mean this

#include <stdio.h>
#include <stdlib.h>

void
printValue(int y)
{
    if (++y > 100)
        return;
    printf("%d\n", y);
    printValue(y);
}

int
main()
{
    printValue(0);
    return 0;
}

7

solved Converting an iterative algorithm to a recursive one [closed]