You are on page 1of 2

Er.

Puneet kumar tyagi


AIM :- Write a program for NEWTON-RAPHSON METHOD

#include<stdio.h>

#include<conio.h>

#include<math.h>

float f (float x)

return((.51)*(x)-sin(x));

float df(float x)

return((.51)-cos(x));

float ddf(float x)

return(sin(x));

void main()

float x1,x2,x3,y1,y2,y3,a;

int i,n;

clrscr();

printf("\ n enter value of intial guess x1");

scanf("%f",& x1);

printf("\ n enter the no. of iterations");;

scanf("%d", & n);


Er.Puneet kumar tyagi
y1=f(x1);

y2=df(x1);

y2=ddf(x1);

a=((y1*y3)/(y2*y2));

while(fabs(a)>1)

printf("\ n enter value of x1 again");

scanf("%f", & x1);

y1=f(x1);

y2=df(x1);

y3=ddf(x1);

a=((y3*y1)/(y2*y2));

for(i=1;i<=n;i++);

x2=x1-(y1/y2);

x1=x2;

y1=f(x1);

y2=df(x1);

printf("\n the root x2=%f",x2);

getch();

You might also like