Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- float F(float x) {
- return (x*x)-x-3;
- }
- int main() {
- long double p, q, e1, s;
- cout<<"Podaj wartosc p: ";
- cin>>p;
- cout<<"Podaj wartosc q: ";
- cin>>q;
- cout<<"Podaj wartosc E1: ";
- cin>>e1;
- s = (p+q)/2;
- while (F(q) != 0 && (q-p) >= e1) {
- s = (p+q)/2;
- if(F(p) * F(s) > 0) {
- p = s;
- }
- else {
- q = s;
- }
- }
- if (F(p) == 0) {
- cout<<"p wynosi: "<<p;
- return 0;
- }
- if (F(q) == 0) {
- cout<<"q wynosi: "<<q;
- return 0;
- }
- cout<<"Miejsce zerowe wynosi: "<<s;
- }
Advertisement
Add Comment
Please, Sign In to add comment