Javatpoint Logo
Javatpoint Logo

C program for secant method

The Secant Method stands out as an effective and potent numerical method for solving quadratic equations. The Secant Method is renowned for its precision and ease of use, and it is especially effective at locating the roots of quadratic equations. In this article, the principles of the Secant Method will be examined, along with its application in C programming and a practical example complete with code and results.

The Secant Method is a type of iterative numerical method for approximating an equation's roots. The Secant Method avoids the need for derivatives, in contrast to Newton's Method and other approaches, earning it the nickname "Newton's Method without Division". The main concept behind the method is to convert a quadratic equation into two linear equations, which are then used to calculate the root values.

Ways to Implement the Secant Method:

The Secant Method in C programming can be implemented in the following ways:

  • The first step is to transform the quadratic problem into a system of linear equations. For instance, take the equation 3x2 + 4x - 8 = 0. Through manipulation, it is changed to 3(x + 2)2 = 8. Once it is done, the equation can be recast as two linear expressions: x + 2 = sqrt(8/3) and 3x + 6 = sqrt(8/3).
  • 'a' and 'b' stand for the user's initial guesses when asked for them. The approach might not work if these assumptions are made if f(a) and f(b) are equal.
  • Inputs for the required accuracy and the maximum number of iterations should be gathered. Until the target accuracy is attained or the maximum iteration count is reached, the method will iterate to improve the root estimate.
  • Create an iteration loop to cycle through the algorithm. Apply the following equation to determine the next approximation, "c": c = (a * f(b) - b * f(a)) / (f(b) - f(a)). Update 'a' and 'b' after that in preparation for the following iteration.
  • After that, display the current iteration's number and the value of "c" in the output. Continue the loop until the accuracy is less than the desired absolute value of f(c).



Enter the values of a and b:
1 2
Enter the values of allowed error and maximum number of iterations:
0.0001 10
Iteration No-1    x=2.333333
Iteration No-2    x=1.897810
Iteration No-3    x=1.751373
Iteration No-4    x=1.730823
Iteration No-5    x=1.732114
The required solution is 1.732114


In this C program, the Secant Method is used to roughly get the root of the equation x3 - 4 = 0. Initial guesses 'a' and 'b' are entered by users, along with the number of iterations 'n' and the permitted error 'e'. To get closer to the root, it changes 'a' and 'b' iteratively, outputting the most recent approximation after each update. When the fault occurs within 'e' iterations or 'n' iterations, the program terminates.


In conclusion, the Secant Method demonstrated to be an effective method for approximating the roots of quadratic equations with high precision. It is effective and trustworthy because of its distinctive method of converting quadratic problems into linear ones combined with iterative refining. This article discussed the fundamentals of the Secant Method, how it may be applied to C programming, and presented a useful code example. By mastering the Secant Method, programmers expand their arsenal for numerical analysis and get a flexible method for solving challenging mathematical problems. The given example shows how effective it is in practice and demonstrates how quickly it can converge to precise root estimations.

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA