From the course: C: Data Structures, Pointers, and File Systems

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Solving math puzzles

Solving math puzzles - C Tutorial

From the course: C: Data Structures, Pointers, and File Systems

Start my 1-month free trial

Solving math puzzles

- [Narrator] Beyond the C language's basic math operators, you must turn to functions to perform certain arithmetic operations. For example, C lacks a power operator. To raise a number to a certain power, you use the pow function, as shown in this code. The function is prototyped in the math.h header file included at line two and the pow function itself is nestled in the printf statement at the end of line nine. The first argument is the base. The second is the exponent. So the effect of this code is to raise two to powers from zero through 20 as set in the four loop. Arguments for the pow function are doubles which is why variable a is set as a double at line six, and why all the literal values shown in this code in the four loop and at line nine, are specified with dot zero, making them floating point, and not integers. You'll then run. Behold, powers of 2. In this code, I'm using the square root function at line 11 to generate square roots of the double values stored in variable a.…

Contents