next up previous contents
suivant : A.3 Itérateurs et applications remonter : A. Corrigés des programmes précédent : A.1 Fonctions récursives

A.2 Fonctions récursives terminales

recursionTerminale.c


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


long factorielleR(long n, long acc)
{
    printf("(%ld, %ld)\n", n, acc);
    if (n == 0)
        return  acc;
    return factorielleR(n-1, acc * n);
}

long factorielle(long n)
{
    return factorielleR(n, 1);
}

int main()
{
    long a = 4;
    printf("%ld ! = %ld\n", a, factorielle(a));
    getch();
    return 0;
}



Alexandre
2009-07-20