include the header file For example, file inputdouble.c includes the header file getdouble.h, so it can use the function getdouble() #include “getdouble.h”
library has a header file, which is the interface (list of function prototypes) to the library functions The header file also contains macros and variables Library files are binary files in machine code Header files are text files in the C language
Description <assert.h> : Diagnostics used to detect logical errors <ctype.h> : Character functions to see if uppercase, etc. <errno.h> : Test error codes reported by library functions <float.h> : Macro constants for floating-point limits <limits.h> : Macro constants for integer limits
Description <locale.h> : Locale-specific I/O for numbers, currency, etc. <math.h> : Mathematical functions <setjmp.h> : Non-local jumps to different functions <signal.h> : How to handle signals, such as division by zero <stdarg.h> : Functions can have infinite arguments
Description <stddef.h> : Macro and variable definitions, such as NULL <stdio.h> : Input and output functions <stdlib.h> : Utility functions, such as numeric conversions <string.h> : String functions <time.h> : Time and date functions
numbers return a positive number with the same value Positive numbers return the same positive number Function prototype: double fabs(double x); Parameter can be a double or integer (automatically converts it to a double), but always returns a double
to an integer const double PI = 3.141592; const int TWO = 2; printf(“%f\n”, fabs(-PI)); //3.141592 printf(“%f\n”, fabs(TWO)); //2.000000 printf(“%d\n”, (int)fabs(TWO)); //2
is the Base of Natural Logarithms An irrational number and important math constant e = 2.7182818284590452353602874713526624977572... e = 1/0! + 1/1! + 1/2! + 1/3! + 1/4! + ... Discovered from compound interest calculations Also called Napier's Constant or Euler's Number
e (log e x) Errors occur if x<=0 Function prototype: double log(double x); const int ONE = 1; const double E = exp(ONE); printf(“%f\n”, log(ONE)); //0.000000 printf(“%f\n”, log(E)); //1.000000
that is used to generate a random sequence To set the seed, we need to use the srand() function, which is part of the stdlib.h library Function definition: void srand(unsigned int seed);
clock to generate the seed for the random number generator Function time(NULL) returns the "UNIX time," which is the number of seconds since January 1, 1970 NULL is the NULL pointer, which has the value zero (0) srand(time(NULL));
stdlib.h library Function prototype: int rand(void); Generates a pseudo-random number from zero (0) to RAND_MAX (32,767 on UH UNIX) Each time a program containing rand() is executed the same values will be generated, so that is why we seed it with a different value each time (UNIX time)