F
hier noch ein paar Änderungen
#include <iostream>
#include <stdio.h>
double grade(double x)
{
return -2*x-5.387;
}
double parabel(double x)
{
return x*x-5.381;
}
double nullstelle(double a,double b,double Epsilon,double (*f)(double)) //übergebe eines Funktionspointers
{
double m;
do
{
m=(b-a)/2+a;
if (f(m)*f(a)<0) //die Nullstelle liegt in dem bereich
{ //in dem ein Vorzeichenwechsel statt findet
b=m; //also wenn a<0 und m>0 oder umgekehrt.
} //wenn dem so ist, ist a*m < 0
if(f(m)*f(b)<0)
{
a=m;
}
}while(f(m)*f(m)>Epsilon*Epsilon);
return m;
}
int main()
{
printf("%f\n",nullstelle(-10,10,0.00001,grade));
printf("%f\n",nullstelle(-10,10,0.0001,parabel));
}