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 - C Tutorial
From the course: C: Data Structures, Pointers, and File Systems
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.…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
Solving math puzzles3m 32s
-
Creating random numbers3m 42s
-
Working with time functions3m 54s
-
Sorting data4m 8s
-
Debugging your code2m
-
Using a debugger4m 53s
-
Writing your own header file2m 53s
-
Mixing multiple source code files4m
-
Challenge: Lotto simulation1m 18s
-
Solution: Lotto simulation2m 29s
-
-