math.h library

Math.h library


  • We’ll be using the word function more and more. So far, we’ve taken it for granted and haven’t paid attention to what it means. We’ve used functions like printf() and scanf().
    In essence, a function is just a set of commands to carry out some goal (execute a set of commands to achieve the goal). For an example, it can be just to show some text on the screen or it can be to find the square root of a number.
  • So far we’ve used variables to print some numbers stored in variables using the printf() function, however we can also use functions themselves as arguments to find and print a value.
    E.g. the square root function returns a number it calculates and we can either store it in a variable or directly print it out without storing it.
    The same goes for power function.
  • To find the N-th root of a number, we can use the properties of powers as it’s done on the line 27. It’s important to use a fraction format here (1 -> 1.0). It’s because of how computers handle integers and floating point numbers.
  • When using addition functions (powers, roots, sin, cos, tan, etc.) in equations, the results of those functions are found (returned) and “replaced” into the equation. This property helps us to also use them directly in printouts without storing them.