Tutorial de Lenguaje C                                                                                               Dr. Roberto Gómez


VERSIÓN ARREGLO CON SWITCH

/* Programa de opicon de funciones usando un switch */

#include <math.h>


        main()
{

                    static double (*action[3])(double) = ffabs, sqrt, expg;
                    int i;
                    double x,y;

                    x=1.0;
                    printf(''De un numero (0-2): '');
                    scanf(''%d'',&i);

                    switch {
                                        case 0: y = fabs(x);
                                        break;

                                        case 1: y = sqrt(x);
                                        break;

                                        case 2: y = exp(x);
                                        break;
                                  }

                    printf(''nn encontramos: %lf nn'',y);
}
 

MENÚ PRINCIPAL