using library functions
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 PresentationTRANSCRIPT
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
Most used headersMost used headers• stdio.h
• string.h
• stdlib.h
• math.h
• graphics.h
• …
Functions in math.hFunctions in math.h• sin• cos• tan• acos• asin• atan• log• pow• …
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);
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