When a C language operator can't do the math, you turn to a math function, most of which are defined in the math.h header file. The pow() function raises a value to a specific power. The sqrt() function returns the square root of a value. Other mathematical functions are available in the standard C library or in the math library. Keep in mind when doing trigonometry programming that the C language trig functions use radians to express angles, not degrees.
- [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 …
- Working with arrays
- Building a structure
- Creating an array of structures
- Testing characters
- Working with strings in C
- Using pointers to manipulate data
- Manipulating files
- Using command-line arguments
- Working with time functions
Skill Level Intermediate
1. Arrays and Structures
2. Characters and Strings
4. Files and the Operating System
5. The Interesting and Extraordinary
Next steps1m 52s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.