C/Visual C - ayuda con este programa

 
Vista:

ayuda con este programa

Publicado por deivis (1 intervención) el 17/12/2009 11:07:56
hola, el siguiente programa al ejecutarlo en Dev-C no me da ningun problema.Pero al ejecutarlo en SSH Secure Shell (en linux), me da los siguientes errores...

biseccion.c: En la función âbisectionâ:
biseccion.c:25: aviso: declaración implícita incompatible de la función interna âexitâ
/tmp/ccMaNJpx.o: In function `f':
biseccion.c:(.text+0x21): undefined reference to `sin'
biseccion.c:(.text+0x37): undefined reference to `cos'
collect2: ld devolvió el estado de salida 1

otra duda, para que sirve los argumentos del main en este caso en concreto??

Gracias de antemano!

este es el programa:

/* The bisection method for finding a root of an equation.
*/
#include <stdio.h>
#include <math.h>

#define LEFT 0.0
#define RGHT 1.0

#define NOT_CONVERGING (-1)

double f(double x);

double bisection(double, double, double, int);

int
main(int argc, char **argv) {
double x;
x = bisection(LEFT, RGHT, 1e-6, 1000);
printf("(main) x = %.10f, f(x) = %12.10f\n", x, f(x));
x = bisection(LEFT, RGHT, 1e-8, 1000);
printf("(main) x = %.10f, f(x) = %12.10f\n", x, f(x));
x = bisection(LEFT, RGHT, 1e-10, 1000);
printf("(main) x = %.10f, f(x) = %12.10f\n", x, f(x));
return 0;
}

double
f(double x) {
return sin(5*x) + cos(10*x) + x*x/10;
}

double
bisection(double x1, double x2, double eps, int limit) {
double fx1, fx2, mid, fmid;
int iterations=0;
fx1 = f(x1);
fx2 = f(x2);
while (x2-x1 > eps) {
iterations = iterations+1;
if (iterations==limit) {
exit(NOT_CONVERGING);
}
mid = (x1+x2)/2;
fmid = f(mid);
if (fx1*fmid < 0) {
/* root is to left of middle */
x2 = mid;
fx2 = fmid;
} else {
/* root is to right */
x1 = mid;
fx1 = fmid;
}
}
printf("(bisection) eps=%.1e, iterations=%d\n",
eps, iterations);
return (x1+x2)/2;
}

/* =====================================================================
Program written by Alistair Moffat, as an example for the book
"Programming, Problem Solving, and Abstraction with C", Pearson
SprintPrint, Sydney, Australia, 2003.

See http://www.cs.mu.oz.au/~alistair/ppsaa/ for further information.

This version prepared January 29, 2003.
================================================================== */
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder