Skip to content

TP5_ej9 #14

@MGuthmann05

Description

@MGuthmann05

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions