怎么用递归实现从N个不同的字母中选出M个的所有组合,并打印

如何用递归实现从N个不同的字母中选出M个的所有组合,并打印?
菜鸟算法问题,求解决:

要求,给定任意数组,例如 char arr[4]={'a', 'b', 'c', 'd'}; 打印出任意m个元素的组合,
例如m=3, 则要按照以下顺序输出:abc abd acd bcd
要求用c语言递归实现。各位高手帮忙想想,先谢过。

------解决方案--------------------
C/C++ code

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

void func(char *f, char *l, char res[], const int M, int cnt = 0)
{
    int i;
    
    if (f == l || M <= cnt)
    {
        if (M == cnt)
        {
            for (i = 0; i < M; ++i)
            {
                printf("%c ", res[i]);
            }
            printf("\n");
        }
    }
    else
    {
        if (f < l)
        {
            res[cnt] = *f;
            func(f + 1, l, res, M, cnt + 1);
            func(f + 1, l, res, M, cnt);
        }
    }
}

int main()
{
    char src[] = {'a', 'b', 'c', 'd'};
    char res[sizeof(src) / sizeof(src[0])];
    
    func(src, src + sizeof(src) / sizeof(src[0]), res, 3);
    
    system("pause");
    return 0;
}