Sommaire


La fonction FoG modifier

Ici on passe les deux fonctions f et g à la fonction FoG(). Rappel fog() cela veut dire que l'on commence par calculer g(a) puis on l'applique à f. Soit f(g(a)).

La même fonction peut calculer gof, fog et fof...

  c01.c
/* ------------------------------ */
/* Save as c01.c                  */
/* ------------------------------ */
#include    <stdio.h>
#include     <math.h>

/* ------------------------------ */
double f(
double x)
{return( pow(x,2.));}
/* ------------------------------ */
char  feq[] = "x**2";
/* ------------------------------ */
/* ------------------------------ */

/* ------------------------------ */
double g(
double x)
{return(2.0*x + 3.0);}
/* ------------------------------ */
char  geq[] = "2.0*x + 3.0";
/* ------------------------------ */
/* ------------------------------ */

/* ------------------------------ */
double FoG(
double (*P_F)(double x),
double (*P_G)(double x),
double a
)
{
 return((*P_F)( ((*P_G)(a))) );
}
/* ------------------------------ */
/* ------------------------------ */

int main(void)
{
double a = 2.0;

 printf(" f : x-> %s\n", feq);
 printf(" g : x-> %s\n", geq);
 printf(" \n\n");

   printf(" f(g(%.0f)) = %6.1f\n", a, FoG(f,g,a));
   printf(" g(f(%.0f)) = %6.1f\n", a, FoG(g,f,a));
   printf(" f(f(%.0f)) = %6.1f\n", a, FoG(f,f,a));

 printf("\n\n Press return to continue.\n");
 getchar();

 return 0;
}

/* ------------------------------ */
/* ------------------------------ */

Résultat :

f : x-> x**2
g : x-> 2.0*x + 3.0
.
f(g(2)) = 49.0
g(f(2)) = 11.0
f(f(2)) = 16.0
.
Press return to continue.