-->

Facebook

Jasper Roberts - Blog

Monday, March 2, 2015

A C Program to represent N-R Method.

#include<conio.h>
#include<stdio.h>
double f(double x)
{
return (x*x*x+2*x*x+10*x-20);
};
double df(double x)
{
return (3*x*x+4*x+10);
};
void main()
{
int iter,ctr=1;
double x0,x1,l1,l2,r,x2;
clrscr();
printf("\nEnter the first approximate value : ");
scanf("%lf",&x0);
printf("\nEnter the second approximate value : ");
scanf("%lf",&x1);
printf("\nEnter the number of itteration : ");
scanf("%d",&iter);
x2=((x0+x1)/2);
while(ctr<=iter)
{
r=x2-(f(x2)/df(x2));
printf("\nAfter %d itteration root is = %.4lf",ctr,r);
x2=r;
ctr++;
}
printf("\n\nThe approximate root is = %.4lf",r);
getch();
}
RELATED TOPICS
A C Program to represent the Bisection Method.
A C Program to represent Secant Method.

No comments:

Post a Comment