001
18.01.2007, 19:13 Uhr
~XHatebreedX
Gast
|
C++: |
#include<stdio.h> #include <ctype.h> #include <math.h> double bisektion(double a,double b) { double c; c=(a+b)/2; return c; } double f(double x) { double erg;
erg=x*x-2; return erg; }
double vorz(double x) { if (x<0) return 0; else return 1; } double betrag(double a) { if(a<0) { a=-a; return a; } } main() { double a,b,c,feld[50][4]; int i=0; printf("erster Intervall"); scanf("%lf",&a); printf("zweiter Intervall"); scanf("%lf",&b); printf("Nr. \t c \t a \t b \t a-b \n"); do { c=bisektion(a,b); if(vorz(f(a))==vorz(f(c))) { a=c; } else { b=c; } i++; feld[i][0]=i+1; feld[i][0]=c; feld[i][1]=a; feld[i][2]=b; feld[i][3]=a-b; printf("%lf %lf %lf %lf\n",feld[i][0],feld[i][1],feld[i][2],feld[i][3]); }while(betrag(a-b)>pow(10,-3)); }
|
|