Square root without using library function

 

While performing any mathematical problems we often use library function. It is advantageous as it saves time but it is a good practice to code each part of program if we are in beginner phase. To calculate square root of a number use use sqrt function included in "math.h" header file.  So, instead of using that library function, we are using fixed point iteration (a square root calculation method). 


How to download code?

  • Click here for source code.
  • New window will open where there is a source code of this project. Download the file.
  • Remember that this project runs in Dev C++.


Demo of this game :


  

For more source code and tutorial, SUBSCRBE to my YouTube channel. 


Development platform

C++ language has been used to develop this project.

 

Compiler

Dev C++ has been used as compiler in this project whose version is 5.11.


Header files used

The header files used in this project are as follows :

  1. Iostream
  2. Conio


Library functions

The following library functions has been used :

  1. Under iostream header file
    1. Main
  2. Under conio header file
    1. Getch

 

Concepts used

Topics/ concepts of this language that you need to know for making this type of game :

  1. Do while conditional statement


Logic description

This method is also known as direct substitution method or method of iteration of fixed iteration. It is applicable if the equation f(x)=0 can be expressed as x = g(x). If x0 is the initial approximation to the root, then the next approximation to the next root is given by, 

        x1 = g(x0)

and the next iteration will be 

       x2 = g(x1)

This method converges if |g(x0)|<1.

No comments:

Post a Comment

Article Ad1