Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#include <stdio.

h>
#include <math.h>

int main() {
int e;
double x1, x2, y1, y2, srodek_x, srodek_y;

printf("Podaj precyzję, powinna być większa od 0: ");


scanf("%d", &e);

x1 = 0;
x2 = 2;

for (int i = 1; i <= e; i++) {

y1 = pow(x1, 3) - 2 * pow(x1, 2) - x1 + 1;
y2 = pow(x2, 3) - 2 * pow(x2, 2) - x2 + 1;

if (y1 * y2 <= 0) {

srodek_x = (x1 + x2) / 2.0;


srodek_y = pow(srodek_x, 3) - 2 * pow(srodek_x, 2) - srodek_x + 1;

if (srodek_y == 0.0) {

x1 = srodek_x;
x2 = srodek_x;

} else if (srodek_y * y1 < 0.0) {

x2 = srodek_x;

} else if (srodek_y * y2 < 0.0) {

x1 = srodek_x;

printf("\ne = %d Przybliżona wartość miejsca zerowego wynosi: %.10lf",


i, (x1 + x2) / 2);

}
}

return 0;
}
Poprawiłem jedynie kilka drobnych błędów w formie i zachowałem logiczną strukturę
programu. Teraz kod jest bardziej czytelny, a komunikaty są sformułowane w języku
polskim.

You might also like