Code for Newtons rapson method in C

C code to implement Newtons rapson method .  Compiled in DEV C++

website_caption1

#include<stdio.h>
#include<conio.h>
#include<math.h>
float f(float);
float f1(float);
float f(float x)
{
      return(pow(x,3)-8*x-4);
}
float f1(float x)
{
      return(3*pow(x,2)-8);
}
main()
{
      float e, x, x1;
      int k=0;
      printf("Enter the values of x");
      scanf("%f",&x);
      printf("Enter the value of e");
      scanf("%f",&e);
       do
                     {
                         x1=x;
                         x=x-(f(x)/f1(x));
                         k++;
                     }
                     while(fabs(x-x1)>e);
                     printf("%f %d", x, k);
      getch();
}

 website_caption1

 You might be also interested in :

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s