Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this program you will approximate the cube root of a number n using Newton\'s

ID: 3857806 • Letter: I

Question

In this program you will approximate the cube root of a number n using Newton's method. This method starts with an initial guess x_0 close to 3 squareroot n, and at the k^th step calculates x_k + 1 = 1/3 (2x_k + n/x^2_k). As k gets larger an larger, x_k almostequalto 3 squareroot n. Your program must take the number n, initial guess x_0, and number of steps m and print x_m with exactly 5 decimal places using printf ("%0.51f", x_m): [rsgysel@pc17] $ /cuberoot Enter the integer you wish to find the cube root of: 2 Enter your first guess and number of steps: 1 1000 The cube root of 2 is approximately 1.25992

Explanation / Answer

#include<stdio.h>

int main()

{

float x_0,x,x_m,n;

int m,i=1;

printf("Enter integer you wish to find the cube root of: ");//prompt user to enter number

scanf("%f",&n);

printf(" Enter your first guess and number of steps: ");

scanf("%f %d",&x_0,&m);

x_m=(1.0/3.0)*((2*x_0)+(n/(x_0*x_0)));

while( i<m)

{

x=x_m;

x_m=(1.0/3.0)*((2*x)+(n/(x*x)));

i++;

}

printf(" The cube root of %.0f is approximately %.5f",n,x_m);

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote