-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Hola, tengo una duda con este ejercicio. Cuando lo ejecuto usando el intervalo [-1;1] me dice que -9.38176e-14 es raíz (debería ser 0). ¿Debería buscar redondear el resultado? ¿O hay algo del código que es incorrecto?
#include <stdio.h>
#include <math.h>
#include "getnum.h"
#define INCREMENTO 0.0001
void funcion(double left, double right);
double eval(double v);
int main()
{
double izq, der;
izq = getdouble("Inserte su extremo izquierdo del intervalo:\n");
der = getdouble("Inserte su extremos derecho del intervalo:\n");
funcion(izq, der);
return 0;
}
void funcion(double left, double right)
{
for(double x = left; x <= right; x += INCREMENTO)
{
if (eval(x) == 0 || (x - INCREMENTO > 0 && x + INCREMENTO < 0) || (x - INCREMENTO < 0 && x + INCREMENTO > 0))
{
printf("%g es raiz\n", x);
}
x += INCREMENTO;
}
}
double eval(double v)
{
return sin(v);
}Metadata
Metadata
Assignees
Labels
No labels