Problem 8A 5 points Write a C program to find the roots for
Problem 8A (5 points)
 Write a C program to find the roots for the following polynomial using Newton-Raphson method. F(x) = Ax^3 + Bx^2 + Cx + D Where A, B, C and D are coefficients/constant of the polynomial. The program should ask the user to
 enter the values for each and also the initial value of estimated root value. Use 10 decimal places for precision.
Solution
 #include<stdio.h>
 #include<stdlib.h>
 #include<math.h>
int my_power,i=0,count=0,f=0;
 int coefficient[10]={0};
 float x1=0,x2=0,t=0;
 float fx1=0,fdx1=0;
int main()
 {
printf(\"Finding root for three degree polynomial Ax^3+Bx^2+Cx+D\ using Newton-Raphson method\ \");
my_power=3;int j=0;
 printf(\"Enter the value for following coefficientficent\ \");
 for(i=my_power;i>=0;i--)
 {
 printf(\"\ \\t%c::\",\'A\'+j);
 scanf(\"%d\",&coefficient[i]);
 j++;
 }
printf(\"\ \");
 printf(\"\ \ initial root estimate : \");
 scanf(\"%f\",&x1);
int cc=0;
 do
 {
 count++;
 fx1=fdx1=0;
 for(i=my_power;i>=1;i--)
 {
 fx1+=coefficient[i] * (pow(x1,i)) ;
 }
 fx1+=coefficient[0];
 for(i=my_power;i>=0;i--)
 {
 fdx1+=coefficient[i]* (i*pow(x1,(i-1)));
 }
 t=x2;
 x2=(x1-(fx1/fdx1));
x1=x2;
 cc++;
printf(\"\ %d : Estimate : %.13f \",count,x2);
}while(cc<5);
 printf(\"\ \\t Approximate solution = %.13f\",x2);
   
 }
===========================================================================
akshay@akshay-Inspiron-3537:~/Chegg$ gcc newton.c -lm
 akshay@akshay-Inspiron-3537:~/Chegg$ ./a.out
 Finding root for three degree polynomial Ax^3+Bx^2+Cx+D
 using Newton-Raphson method
 Enter the value for following coefficientficent
A::1
B::3
C::-1
D::-4
initial root estimate : 1.0
1 : Estimate : 1.1250000000000   
 2 : Estimate : 1.1149754524231   
 3 : Estimate : 1.1149076223373   
 4 : Estimate : 1.1149076223373   
 5 : Estimate : 1.1149076223373   
    Approximate solution = 1.1149076223373


