1 / 7

What are f unctions?

What are f unctions?. 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. Just some stuff the compiler uses and the user

dawn
Download Presentation

What are f unctions?

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. What arefunctions? 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 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

  5. 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: • gccprogram.c –lm –o executable • Or • gccprogram.c –o executable –lm (this way is better)

  7. Law of Cosines Leg 1 Leg 2 Hypotenuse

More Related