#include<stdio.h>
#include<math.h>
#include<conio.h>
int main(){
int a[25],n,i,b[25],iter,j;
double t,x,y,z,sum=0,deriv=0,c[100];
printf("Enter the degree: ");
scanf("%d",&n);
printf("Enter the coefficients: \n");
for(i=n;i>=0;i--){
printf("enter the coefficient of x^%d: ",i);
scanf("%d",&a[i]);
}
printf("The polynomial is: ");
for(i=n;i>=0;i--){
printf("(%d)x^%d+",a[i],i);
}
printf("\n");
for(i=n;i>=0;i--){
b[i]=a[i]*i;
}
printf("The derivative of the polynomial is: ");
for(i=n-1;i>=0;i--){
printf("(%d)x^%d+",b[i+1],i);
}
printf("\n");
printf("For newton raphton method enter the number of iterations:");
scanf("%d",&iter);
printf("Enter the value of x:");
scanf("%lf",&x);
for(j=0;j<=iter;j++){
for(i=n;i>=0;i--){
sum+=a[i]* pow(x,i);
}
y=sum;
sum=0;
for(i=n-1;i>=0;i--){
deriv+=b[i+1]* pow(x,i);
}
z=deriv;
deriv=0;
t=(x-y/z);
c[j]=t;
if(c[j]==c[j-1])
break;
printf("Values of x%d= %lf \n",j,t);
x=t;
}
}