Advertisement
namkongkirat

Secant Method

Dec 23rd, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<stdlib.h>
  4. #include<math.h>
  5.  
  6. float function(float);
  7. int main() {
  8.     float a, A, b, B, c, C, tc, m;
  9.     printf("Enter values of x1 and x2:\n");
  10.     scanf("%f%f",&a,&b);
  11.     A=function(a);
  12.     B=function(b); 
  13.     if(A==B){
  14.         printf("Error, Enter valid values.");
  15.         exit(1);
  16.     }
  17.     tc=b;
  18.     do {
  19.         A=function(a);
  20.         B=function(b);
  21.         c=(((a*B)-(b*A))/(B-A));
  22.         a=b;
  23.         b=c;
  24.         m=tc-c;
  25.         tc=b;
  26.     }while(fabs(m)>0.0009);
  27.     printf("\n\nThe root is: %.4f",c);
  28.     getch();
  29. }
  30.  
  31. float function (float x) {
  32.     return ((x*x)-(8*x)-14);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement