Showing posts with label OUTPUT. Show all posts
Showing posts with label OUTPUT. Show all posts

PROGRAM (TO FIND APPROXIMATE ROOT OF THE LINEAR EQUATION BY NEWTON-RAPHSON METHOD)

PROGRAM
FINDING APPROXIMATE ROOT OF A LINEAR EQUATION BY NEWTON-RAPHSON METHOD

#include<stdio.h>
#include<math.h>
#include<conio.h>
float f(float x)
{
 return (x*x)-2*x;
}
float df(float y)
{
 return(2*y)-2;
}

int main()
{
 float x0,x1,h;
 int n;
 clrscr();
 printf("\nenter the max no. of iterations");
 scanf("%d",&n);
 printf("\nenter the initial approximate value for the function (x*x)-(2*x)");
 scanf("%f",&x0);
 for(int i=0;i<n;i++)
 {
  h=f(x0)/df(x0);
  x1=x0-h;
  printf("\n at the iteration %d, root is %f\n",(i+1),x1);
  if(fabs(h)<0.001)
  {
   printf("\nafter %d iteration final root is %f",(i+1),x1);
  }
  x0=x1;
 }
 getch();
 return 0;
}

OUTPUT:-


PROGRAM (TO FIND APPROXIMATE ROOT OF A LINEAR EQUATION BY BISECTION METHOD)

PROGRAM
FINDING APPROXIMATE ROOT OF A LINEAR EQUATION BY BISECTION

#include<stdio.h>
#include<math.h>
#include<conio.h>
float f(float x)
{
 return (x*x*x)-4*x-9;
}

int main()
{
 float x0,x1,a,b;
 int i=1,n;
 clrscr();
 printf("\nenter the values of a, b and max no. of iterations\n");
 scanf("%f %f %d",&a,&b,&n);
 x0=(a+b)/2;
 printf("\nat iteration %d, root is x= %f\n",i,x0);
 i++;
 while(i<=n)
 {
  if(f(a)*f(x0)<0)
  b=x0;
  else
  a=x0;
  x1=(a+b)/2;
  printf("at intersect %d, root is x=%f\n",i,x1);
  if(fabs(x1-x0)<0.001)
  {
   printf("after %d iterations, the value of root is %f\n",i,x1);
   break;
  }
  x0=x1;
  i++;
 }
 getch();
 return 0;

}

OUTPUT:-



Powered by Blogger.

Popular Posts