Every high-level programming language provides many functions that can be used whenever and wherever you wish. Functions are nothing more than a block of statements packaged as a unit that has a name and performs a specific task.

Notice: Not every computer language uses the term “function”. For example Java, C#, Visual Basic, and Python are using the term “method”.

To better understand functions, let’s take Heron’s iterative formula that calculates the square root of a positive number.


  • y is the number for which you want to find the square root
  • xn is the n-th iteration value of the square root of y

Please don’t be disappointed! No one at the present time calculates the square root of a number this way. Fortunately, high-level programming languages such as PHP, Java, C++, C#, Visual Basic, and Python  include a function for that purpose! This function, which is actually a small subprogram, has been given a name, for example sqrt, and the only thing you have to do is call it by its name and it will do the job for you. This function probably uses Heron’s iterative formula, or perhaps a formula of another ancient or modern mathematician. The truth is that you don’t really care! What really matters is that this function gives you the right result! An example is shown here.


If you need more information you can visit PHP Mathematical Functions


If you need more information you can visit Java Mathematical Methods


Notice: Please note that the function sqrt() is defined in the library cmath. Therefore, in order to use the function sqrt, you must include the library cmath using the statement #include <cmath> at the beginning of your program.

If you need more information you can visit C++ Mathematical Functions


If you need more information you can visit C# and Visual Basic Mathematical Methods

Visual Basic


Notice: The method sqrt() is not accessible directly in Python, so you need to import math module. A module is nothing more than a file that contains many ready-to-use functions (or methods). Python incorporates quite a lot such modules, but, if you wish to use a function or a method included in one of those modules, you need to import that module into your program.

If you need more information you can visit Python Mathematical Methods

Leave a Reply

Your email address will not be published. Required fields are marked *

This article is taken from a book of mine. If you enjoyed it, please visit my author's page inand check out all of my books!