#include#include #include #define f(x) 2*x*x+4*x-10 #define E 0.0001 int main(){ int count=0; float x0, x1, x2, f1, f2, err; clrscr(); printf("Enter value of x0: "); scanf("%f", &x0); printf("Enter value of x1: "); scanf("%f", &x1); printf("FirstValue\tFx\tSecondValue\tFx\n"); do{ count++; f1=f(x0); f2=f(x1); x2=x1-(((x1-x0)*f2)/(f2-f1)); printf("%0.4f\t\t%0.4f\t\t%0.4f\t\t%0.4f\n", x0, f1, x1, f2); err=fabs((x2-x1)/x2); x0=x1; x1=x2; }while(err>E); printf("\nRoot: %f", x2); printf("\nSteps: %d", count); getch(); return 0; }
BSc CSIT (Computer Science and Information Technology) Old questions and notes
Thursday, January 11, 2018
Secant Method Program
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment