using library functions

6

Upload: jerry-henry

Post on 31-Dec-2015

23 views

Category:

Documents


0 download

DESCRIPTION

C. Using Library Functions. Basics. You must include the header file in your program # include < > Then use the needed function by calling it You must know the parameters and the return type. Most used headers. stdio.h string.h stdlib.h math.h graphics.h …. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Using Library Functions
Page 2: Using Library Functions

BasicsBasics• You must include the header file in

your program– # include < >

• Then use the needed function by calling it

• You must know the parameters and the return type

Page 3: Using Library Functions

Most used headersMost used headers• stdio.h

• string.h

• stdlib.h

• math.h

• graphics.h

• …

Page 4: Using Library Functions

Functions in math.hFunctions in math.h• sin• cos• tan• acos• asin• atan• log• pow• …

Page 5: Using Library Functions

Parameter and return typeParameter and return type• double sin (double x)– Means the parameter is double

– Return type is also double

– So you should write-

double result, angle;

angle = 45.0 * 3.14159 / 180.0;

result = sin(angle);

Page 6: Using Library Functions

Parameter and return typeParameter and return type• double sin (double x)– If you use int, it will not generate any

error• But you may lose data• Get wrong results

int result, angle;

angle = 45.0 * 3.14159 / 180.0; // angle = 0

result = sin(angle); // result = 0