0% found this document useful (0 votes)
26 views2 pages

NRM

The document describes a C program to find the roots of an equation using Newton's method. The program takes an initial approximation, performs iterations of the method, and prints the results. It finds the square root of 2 as the root of x^2-2.

Uploaded by

PRINCIPAL HAVERI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views2 pages

NRM

The document describes a C program to find the roots of an equation using Newton's method. The program takes an initial approximation, performs iterations of the method, and prints the results. It finds the square root of 2 as the root of x^2-2.

Uploaded by

PRINCIPAL HAVERI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

/* WRITE A ‘C’ PROGRAM TO FIND THE ROOTS OF THE EQUATION USING

NEWTONS RAPHSONS METHOD*/

#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
------------------------------------------------------ */

You might also like