import java.util.Scanner;
public class Newtons {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("the highest power of the function");
int power = in.nextInt();
double[] storage = new double[power + 1];
for (int i = 0; i < storage.length; i++) {
System.out.printf("please input the coefficient of the power %d", i);
storage[i] = in.nextDouble();
}//initialize the function form lowest to highest
System.out.println("the function is");
for (int i = 0; i < storage.length; i++) {
if (i != storage.length - 1) System.out.printf("%.2f x^%d +" + "\t", storage[i], i);
else System.out.printf("%.2f x^%d = 0" + "\t", storage[i], i);
}
System.out.println("please input the x0");
double x0 = in.nextDouble();
while (true) {
double k = 0;
double y0 = 0;
double xi;
for (int i = 1; i < storage.length; i++) {
k += storage[i] * i * Math.pow(x0, i - 1);
}
for (int i = 0; i < storage.length; i++) {
y0 += storage[i] * Math.pow(x0, i);
}
xi = x0 - y0 / k;
if (Math.abs(xi - x0) < 0.000001) {
System.out.println(xi);
break;
} else {
x0 = xi;
}
}
}
}