#include <stdio.h> /*para printf(),scanf()*/
#include <conio.h> /*para getch(),clrscr()*/
#include <stdlib.h>/*para exit()*/
#include <math.h>
//#include <dos.h>
//#define NUMEL 20
double f(double x);
void _error(int n);
enum{INTERVALOS};
enum{SIMPSON1_3=1,SALIR};
int n;
float a,b;
//float X[NUMEL],Fx[NUMEL];
/*Metodo de Simpson 1/3 dada una funcion*/
void Simpson1_3(double a,double b,int n,double *Area)
{
register int i;
double x;
double S0,S1;
double h;
h=(b-a)/(2*n);
S0=S1=0;
for(i=1;i<=(2*n-1);++i){
x=a+((double)i)*h;
if(!(i%2))
S0+=f(x);
else
S1+=f(x);
}
*Area=(h*(f(a)+4*S1+2*S0+f(b))/3.0);
printf("n El area es -> %5.6f nnn",*Area
); }
/*Muestra mensaje de error*/
void _error(int n)
{
static char *msg[]={
"Error en los subintervalos",
""
};
}
/*Funcion a integrar*/
double f(double x)
{
float y;
y = -x * x + 200;
return y;
}
void LeeDatos(int opc)
{
if(opc==SIMPSON1_3){
// clrscr();
printf("n Numero de intervalos (PAR) -> "); }
if((n<1)||((n%2)!=0)){ //numero de iteraciones menor que 0 o impares
_error(INTERVALOS);
}
else
}
/*Muestra el menu en la pantalla*/
void Menu(char *titulo,char *opciones[])
{
int i;
// clrscr();
i=0;
// gotoxy(34,4);
for(;*opciones[i];i++)
printf("tttt %d.- %sn",i
+1,opciones
[i
]); printf("tttt %d.- Salirn",i
+1); }
int main(void)
{
double Area;
int op;
char *opciones[]={"Simpson 1/3",
""
};
do{
// clrscr();
Menu("Metodos de Integracion",opciones);
switch(op){
case SIMPSON1_3: LeeDatos(SIMPSON1_3);
Simpson1_3(a,b,n,&Area);
break;
case SALIR:
// gotoxy(34,20);
printf(" Fin de %s",__FILE__
); //
break;
default:
// gotoxy(34,13);
printf("Opcion no permitida. nnn" ); break;
}
}while(op!=SALIR);
}