/* Zad 3 z zestawu 2. Ćwiczenia z ASD. * Oblicza pierwiastek kwadratowy z x za pomocą algorytmu Herona, * wypisując na wyjściu kolejne wyrazy ciągu w kolejnych iteracjach * Przyjmuje na wejściu liczbę x oraz docelową dokładność * 24 sty 2019 * Michał Krzysztof Feiler (s444368) * */ #include #include static long double c; static long double eps; static long double x; static long long unsigned n; int next() { long double p = x; x = (p + (c / p)) / 2; n++; return fabsl(x - p) >= eps; } void print() { printf("x_%llu=%Lf, ", n, x); } int main() { scanf("%Lf %Lf", &c, &eps); x = c; n = 0; print(); while (next()) print(); print(); return 0; }