Intrinsic Functions (or Library
Functions)
Prewritten programs that are built-in the compiler and
available to be used to compute a singe value.

NOTE: Arguments must be enclosed in parentheses.
An argument can be a constant, variable, or expression.

Trigonometric Functions
- sin: returns a double value for the sine of one
double parameter measured in radians
- cos: returns a double value for the cosine of one
double parameter measured in radians
- tan: returns a double value for the tangent of one
double parameter measured in radians
Example:


Inverse Trigonometric Functions
- asin: returns a double value in radians for the arcsine of
one double parameter
- acos: returns a double value in radians for the arccosine of
one double parameter
- atan: returns a double value in radians for the arctangent of
one double parameter
Example:

Exponential Functions
- exp: returns a double value for e raised to the power of
one double parameter
- pow: returns a double value for the value of the first
double parameter raised to the power of the second double
parameter
- sqrt: returns a double value for the square root of one
double parameter
Example:


Logarithmic Functions
- log: returns a double value for the natural logarithm of
one double parameter
- log10: returns a double value for the logarithm to the
base 10 of one double parameter
Example:


Absolute Value Functions
- abs: returns an integer value of the absolute value of one
integer parameter
- fabs: returns a double value of the absolute value of one
double parameter
Example:


Intrinsic Function Examples
- Argument is a constant:
- atan(1.0) /* Calculates arctangent of 1.0 in radians */
- Argument is a variable:
- abs(x) /* Calculates absolute value of integer x */
- Argument is an expression:
- cos(ang*3.14159/180) /*cosine of angle converted to radians*/

Use of Intrinsic Functions
Intrinsic Functions are used on the right side of an
assignment statement.
- c=sqrt(a*a+b*b);
- y=b*exp(m*x);
- ave=sum/(double)n;
- a=acos(y/r);
(See Appendix B in your C text for an additional list of Intrinsic
Functions and their respective header files)

User Defined Functions
Library functions are important tools to make programs
simpler both to read and write.
To make programs even more simple and easy to follow, we can further
break them down by accomplishing simple tasks by means of writing our
own functions.
Functions are usually written in a program before the main function.
They are written in the same format as main and are given a unique name
(any legal C variable name). The functions can then be called by the
main function.
In the following example, the function info prints information
about the program being run. The function is called in the main
function simply by stating its name with an empty set of parentheses.
When the main function reaches the call, control is transfered to
the info function, which executes, then transfers control back
to main.
#include
#define PI 3.14159
/*Prints information about program*/
void info(void) {
printf("This program calculates the surface area\n");
printf(" and volume of a solid circular cylindar.\n");
printf("You will be asked to enter a radius and a\n");
printf("height. The program will then tell you both\n");
printf("what you entered and the calculated information.\n");
}
int main(void) {
double r, ht, area, vol;
info(); /*Calls function info*/
printf("Enter radius: ");
scanf("%lf", &r);
printf("Enter height: ");
scanf("%lf", &ht);
vol = PI * r*r * ht;
area = 2 * PI * r*r + 2 * PI * r * ht;
printf("For a cylinder of radius %f and height %f:\n", r, ht);
printf("Surface Area = %f\nVolume = %f\n", area, vol);
return(0);
}
Writing more complicated functions will be discussed in a
later lesson.