Home / Computer / C Programming / C Program to Find Root of a Function by Using Newton Raphson Method

C Program to Find Root of a Function by Using Newton Raphson Method

Write a C Program to Find Root of a Function by Using Newton Raphson Method

#include<stdio.h>

#include<conio.h>

#include<math.h>

#define MAX 10

#define E 0.0001

#define f(x)  x*x*x-3*x-2

#define fd(x)  3*x*x-3

int main()

{

    //clrscr();

    int count=0;

    float x0,x1,fx,fdx;

    printf(“\nEnter the initial value of x0\n”);

    scanf(“%f”,&x0);

    begin:

    printf(“\nStep %d”,count+1);

    fx=f(x0);

    printf(“\nvalue of fx%d=%f”,count,fx);

    fdx=fd(x0);

    printf(“\nvalue of fdx%d= %f”,count,fdx);

    x1=x0-(fx/fdx);

    if((fabs(x1-x0)/x1)<E)

    {

        printf(“\nRoot=%f”,x1);

        printf(“\nThe function value=%f”,f(x1));

        printf(“\nNo. of Iritation steps=%d”,count);

    }

    else

    {

        x0=x1;

        count ++;

               if (count<MAX)

               {

               goto begin;

               }

               else

               {

               printf(“It takes more than 10 steps So solution does not converse”);

               }

    }

    getch();

    return 0;

}

people also ask: 

Least square method

C Program Uing Lagranges Interpolation Method

About Arjun Dhamala

Arjun Dhamala is the CEO of thereadmore.com. He is the student of statistics and permanent resident of Nepal. He is one of the Author in this website. Writing, reading and travelling are his hobbies.

Leave a Reply

Your email address will not be published. Required fields are marked *