Informatique

Question

exo sur le langage C
exo sur le langage C

1 Réponse

  • Bonjour,
    Calcule manuellement F1(5) on passe de F1(1) à F1(-1) sans passer par F1(0) .
    #include <stdio.h>
    #include <stdlib.h>

    /* run this program using the console pauser or add your own getch, system("pause") or input loop */

    int F1(int x);
    int F2(int x);

    int main(int argc, char *argv[]) {
    int a;
        a=F1(5);    printf(" F1(5)=%d \n",a);
        a=F1(6);    printf(" F1(6)=%d \n",a);
       
        printf("\n Press enter to continue ...");
        getchar();   
      return 0;
    };

    int F1(int x)
    {
        printf("F1(%d )",x);

        if (x<=0)
            return 0;
        else
            return x+F2(x-1);
    };

    int F2(int x)
    {
        return x+F1(x-1);
    };