Created
September 24, 2014 13:03
-
-
Save Hajto/f959073c241018e84ebc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdio> | |
#include <cmath> | |
#include <cstdlib> | |
const double EPS = 0.000000001; | |
double f(double x){ | |
return 2*x+2; | |
} | |
using namespace std; | |
int main(){ | |
//Zmienne potrzebne do wykonania zadani | |
double a,b,zero; //Okreslają przedział poszukiwań | |
double function_a,function_b,function_zero; //Zmienne, które będą przetrzymywać dane do obliczeń | |
//int licznik_obiegow_petli = 0; | |
//Wczytywanie danych | |
printf("Podaj prosze argument, od którego mam zaczac poszukiwania. \n"); | |
cin>>a; | |
printf("\nPodaj prosze argument, na którym mam zakonczyc poszukiwania. \n"); | |
cin>>b; | |
function_a = f(a); | |
function_b = f(b); | |
//Sprawdzanie czy funkcja spełnia warunki, znaki liczb na krancach przedzialow musza byc rozn | |
for(int i = 64; i > 0 ; i--){ | |
if(abs(a-b) > EPS){ | |
if(abs(function_a - function_b) < EPS){ | |
printf("Zle punkty startowe......"); | |
} else { | |
zero = a - function_a*(a-b)/(function_a-function_b); | |
function_zero = f(zero); | |
} | |
if(abs(function_zero) < EPS){ | |
cout<<"Wynik to: "<<zero; | |
break; | |
} else{ | |
b=a; | |
function_b = function_a; | |
a = zero; | |
function_a = function_zero; | |
} | |
} else { | |
cout<<"Wynik to: "<<zero; | |
} | |
} | |
return 0; | |
system("pause"); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment