Friday, April 10, 2015

Secant Method in C Programming

#include<stdio.h>
#include<conio.h>
#include<math.h>
#define f(x) x*x*x*x-4*x+1
#define E 0.0001
void main()
 {
 float x0,x1,f0,f1,x2;
 int n=1;
clrscr();
pirntf("\n Enter the random guesses:");
scanf("%f %f,&x0,&x1);
a1:
f0=f(x0);
f1=f(x1);
x2=(((x0)*(f1))-((x1)*(f0)))/((f1)-(f0));
printf("\n interation %d = %f",n,x2);
n=n+1;
if(fabs(x2-x1)<E)
{
printf("\n %f",x2);
goto a2;
}
x0=x1;
x1 =x2;
goto a1;
a2:
getch();
}

No comments:

Post a Comment