Saturday, October 24, 2009

PROGRAM TO FIND THE ROOT OF AN EQUATION USING REGULA-FALSE METHOD

// SHUAIB SARKAR
// PROGRAM TO FIND THE ROOT OF AN EQUATION
// USING REGULA-FALSE METHOD

#include"stdio.h"
#include"conio.h"
#include"math.h"
#define FUNC(x) x*x*x-4*x-9

void roots(float x1,float x2)
{
int itr=1;
char trmtr='F';
float a,F1,F2;
do{
F1=FUNC(x1);
F2=FUNC(x2);
a=(x1*F2-F1*x2)/(F2-F1);
if(FUNC(a)<0) x1=a; else x2=a; printf("\n Iterration : %d \t\t %f\t\t %f ",itr,a,FUNC(a)); if(fabs(FUNC(a))<0.0001) { printf("\n=============================================================="); printf("\n Root is : %6.4f\n",a); trmtr='T'; } else { trmtr='F'; itr++; } }while(trmtr=='F'); } void main() { float x1,x2; clrscr(); printf("\n\t\t\t\t REGULA-FALSE METHOD\n"); printf("\n Enter the initial values : "); scanf("%f%f",&x1,&x2); if(FUNC(x1)<0 && FUNC(x2)>0)
{
printf("\n\t\t\t ITERATIONS INVOLVED \n");
printf("\n\t\t\t Aprox Root(s) \t Value of Function\n");
printf("\n===============================================");
roots(x1,x2);
}
else
{
printf("\n ROOTS of the Function don't lie between %3.0f and %3.0f",x1,x2);
getch();
exit(0);
}
getch();
}

No comments:

Post a Comment