Download presentation
Presentation is loading. Please wait.
Published byRolf Johnston Modified over 9 years ago
1
What are functions? 1. A piece of code that performs an operation that can be used by the main program or by other functions 2. A sophisticated if –else statement that always goes into the else part and never into the if part 3.Just some stuff the compiler uses and the user never has to use or see 4. An out of this world thrill ride at the Walt Disney World Resort in Orlando, FL!!!
2
Using Functions Avoid re-inventing the wheel Using existing functions as building-blocks to create new programs “Prepackaged” functions in the C Standard Library can be used. User-defined functions can also be used (talk about this next lecture).
3
Example: Suppose you want to find cos(90°). 90° = π/2 One way would be to calculate the power series: Or, you can just use include the math.h header which contains a built in cosine function.
4
Commonly Used Math Library Functions
6
For your in class assignment Use #include math.h Take a look at /usr/include/math.h and note the #define Use M_PI for pi or define your own pi. Use the function acos(argument) to find the inverse cosine In order to compile using the math library, you must use a compiler flag –lm: gcc program.c –lm –o executable Or gcc program.c –o executable –lm (this way is better)
7
Law of Cosines Leg 2 Leg 1 Hypotenuse
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.