Program No. 1: Program:Solution of Non-Linear Equations Using Bisection Method
Program No. 1: Program:Solution of Non-Linear Equations Using Bisection Method
1
Program:Solution of non-linear equations using Bisection method.
#include<stdio.h>
#include<stdio.h>
#include <math.h>
#include<conio.h>
#define f(x) ((x)*log10(x) -1.2)
void bisect(float a,float b,float *x,int itr)
{
*x=(a+b)/2;
printf("After %d iterations value of root=%10.7f\n",itr,*x);
}
void main()
{
int itr=1,maxitr;
float a,b,x,x1,AE;
printf("Enter the values of a, b, Allowed error, max iterations allowed\n");
scanf("%f%f%f%d",&a,&b,&AE,&maxitr);
printf("\n-----------------------------------------------------------------\n");
bisect(a,b,&x,itr);
do
{
if(f(a)*f(x)<0)
b=x;
else
a=x;
itr++;
bisect(a,b,&x1,itr);
if(fabs(x1-x)<AE)
{
printf("\nAfter %d iterations,the root X=%10.7f\n",itr,x1);
getch();
}
x=x1;
}
while(itr<maxitr);
printf("Max no of iterations allowed are insufficient");
getch();
}
2288847
Pradeep Yadav
ECE-B IV
Output:
2288847
Pradeep Yadav
ECE-B IV