From the course: Complete Guide to C Programming Foundations

Unlock the full course today

Join today to access over 24,500 courses taught by industry experts.

Doing advanced math

Doing advanced math

- [Instructor] The C language has a limited assortment of math operators. For some math operations, you must turn to functions, for example, to perform exponentiation or the square root. In this exercise file, you see the pow function used to raise a value to a certain power. The function is prototyped in the math.h header file, which is shown here. The pow function is nestled within a printf statement. The first argument is the base, the second is the exponent. The function raises two to the powers zero through 20 as set in the four loop. Arguments for the pow functioner doubles, which is why variable A is double and why I've added the .0 to all the literal values. Run the program to behold the powers of two. Now, a problem here, in this environment, is that you need to include the math library. That's different for each IDE. So I'm going to hop over to the command prompt to show you how it works there. Here in a terminal window, I can compile the program. I'll use my compiler name…

Contents