Secant Method in C Programming
See & Learn 😎
#include <stdio.h>
#include <math.h>
#define ans 0.001
#define f(x) pow(x,4)-x-10
int main()
{
float x0, x1, x2;
float f0, f1, f2;
int i = 0;
printf("Enter the value of x(0) and x(1): ");
scanf("%f %f", &x0, &x1);
printf("Enter the function value f0 and f1: ");
scanf("%d %f", &f0, &f1);
do
{
f0 = f(x0);
f1 = f(x1);
x2 = ((x0 * f1) - (x1 * f0)) / (f1 - f0);
f2 = f(x2);
f0 = f1;
f1 = f2;
x0 = x1;
x1 = x2;
i++;
printf("No of Iteration %d ", i);
printf("Root %.4f", x2);
printf("\n");
printf("Value of function %.4f\n", f2);
printf("\n");
} while (fabs(f2) > ans);
return 0;
}
Comments
Post a Comment