#include <bits/stdc++.h>
using namespace std;


double functionVal(double x) {
    return x * x * x - 4.0;
}

double derivativeVal(double x) {
    return 3.0 * x * x;
}

int main() {
    double current, next, f_val, f_deriv, tolerance = 0.0001, approxRoot;
    int iteration = 0;

    cout << "Enter initial guess: ";
    cin >> current;

   
    f_val = functionVal(current);
    f_deriv = derivativeVal(current);
    next = current - (f_val / f_deriv);

    cout << "Iter\tCurrent\t\tf(x)\t\tf'(x)\t\tNext\n";
    cout << iteration << "\t" << fixed << setprecision(8) 
         << current << "\t" << f_val << "\t" << f_deriv << "\t" << next << endl;

    while (true) {
        f_val = functionVal(current);
        f_deriv = derivativeVal(current);

        if (f_deriv == 0) {
            cout << "Derivative is zero. Cannot proceed." << endl;
            return -1;
        }

        next = current - (f_val / f_deriv);
        iteration++;

        cout << iteration << "\t" << fixed << setprecision(8) 
             << current << "\t" << f_val << "\t" << f_deriv << "\t" << next << endl;

        if (fabs((next - current) / next) < tolerance || iteration > 8)
            break;

        approxRoot = next;
        current = next;
    }

    cout << fixed << setprecision(8);
    cout << "Approximate root = " << approxRoot << endl;
    return 0;
}
