Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- const double E=0.000000001;
- double f(double);
- double zerowe(double, double);
- int main() {
- int a, b;
- cout<<"LICZENIE MIEJSC ZEROWYCH"<<endl;
- cout<<""<<endl;
- cout<<"PODAJ PRZEDZIAL: "<<endl;
- cout<<"a: ";
- cin>>a;
- cout<<"b: ";
- cin>>b;
- cout<<zerowe(a,b);
- }
- double zerowe(double a, double b){
- double x;
- if(abs(a-b)>=E){
- double x=(a+b)/2;
- if(f(a)*f(x)<=0)
- {
- return zerowe(a,x);
- }else{
- return zerowe(x,b);
- }
- }
- return x;
- }
- double f(double x)
- {
- return pow(x-2,3);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement