#include <stdio.h>

/* This is a tail-recursive version :-D */
void shift_replace_rec(int *A, unsigned int len, unsigned int delta)
{
    if (delta > 0)
    {
        unsigned int i = len-1;

        /* Get the last element to eventually swap it with the first. */
        unsigned int temp = A[i];

        /* Shift everything one block to the right. */
        for (; i > 0; --i)
        {
            A[i] = A[i-1];
        }

        /* Last element is now the first element. */
        A[i] = temp;

        /* Recurse! */
        shift_replace_rec(A, len, delta-1);
    }
}

void print_array(const int *A, const unsigned int len)
{
    int i;
    for (i = 0; i < 10; ++i)
    {
        printf("%d", A[i]);
    }
    putchar('\n');
}

int main(int argc, char *argv[])
{
    int A[] = {0,1,2,3,4,5,6,7,8,9};
    print_array(A, 10);
    puts("Shifting by 3...");
    shift_replace_rec(A, 10, 3);
    print_array(A, 10);
    puts("Shifting by 7... (Should be the original order now)");
    shift_replace_rec(A, 10, 7);
    print_array(A, 10);
    return 0;
}