NRM
NRM
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#define f(x)(x*x)-2
#define fd(x) 2*x
void main()
{
float a,X[30],b,d,c,e;
int n,i;
clrscr();
printf("Enter the initial approximation\n");
scanf("%f",&a);
printf("Enter the number of itterations\n");
scanf("%d",&n);
printf("-----------------------------------------------------\n");
printf("i\t c\t f(x)\t fd(x)\n");
printf("-----------------------------------------------------\n");
if(a<0)
a=-a;
X[0]=a;
for(i=0;i<n;i++)
{
b=f(X[i]);
d=fd(X[i]);
e=b/d;
X[i+1]=X[i]-e;
printf("%d\t%f\t%f\t%f\n",i+1,X[i+1],f(X[i]),fd(X[i]));
printf("------------------------------------------------------\n");
sleep(1);
}
getch();
}
/*======== OUTPUT ======
Enter the initial approximation
10
Enter the number of itterations
10
-----------------------------------------------------
i c f(x) fd(x)
-----------------------------------------------------
1 5.100000 98.000000 20.000000
------------------------------------------------------
2 2.746078 24.009999 10.200000
------------------------------------------------------
3 1.737195 5.540947 5.492157
------------------------------------------------------
4 1.444238 1.017846 3.474390
------------------------------------------------------
5 1.414526 0.085824 2.888476
------------------------------------------------------
6 1.414214 0.000883 2.829051
------------------------------------------------------
7 1.414214 -0.000000 2.828427
------------------------------------------------------
8 1.414214 -0.000000 2.828427
------------------------------------------------------
9 1.414214 -0.000000 2.828427
------------------------------------------------------
10 1.414214 -0.000000 2.828427
------------------------------------------------------ */