Chapter 1.3 - Illustrate the use of user-defined functions and math functions through sample programs | Part - 2
SAMPE PROGRAM 5 - USE OF MATH FUNCTIONS
We often use standard mathematical functions such as cos, sin, exp, etc. We shall see how the use of a mathematical function in the program. The standard mathematical functions are defined and kept as a part of the C math library.
Chapter 1 - History Of C Programming Language
Download Let us 'C' [pdf] E-BOOK
If we want to use any of these mathematical functions, we must add an #include instructions in the program. Like #define, it is also a compiler directive that instructs the compiler to link the specified mathematical functions from the library. The instruction is of the form
Chapter 1 - History Of C Programming Language
Download Let us 'C' [pdf] E-BOOK
If we want to use any of these mathematical functions, we must add an #include instructions in the program. Like #define, it is also a compiler directive that instructs the compiler to link the specified mathematical functions from the library. The instruction is of the form
#include<math.h>
math.h is the filename containing the required function. Fig. 8 illustrates the use of the cosine function. The program calculates cosine values for angles 0, 10, 20.....180 and prints out the result with headings.
![]() |
Fig. 8 Program using a math function |
Output
![]() | |
|
Another #include instruction that is often required is
#include<stdio.h>
stdio.h refers to the standard O/P input and output functions.
Download Turbo C++ Program Compiler
Download Turbo C++ Program Compiler
The #include Directive
As mentioned earlier, C programs are divided into modules or functions. Some functions are written by users, like us, and many others are stored in the C library. Library functions are groped by category-wise and stored in different files known as header files. If we want to access the functions stored in the library, it is necessary to tell the compiler about the files to be accessed. This is achieved by using the preprocessor directive #include as follows. #include<file name>
the filename is the same of the library file that contains the required function definition. Preprocessor directives are placed at the beginning of a program #allaboutprogramming62.
Comments
Post a Comment
Ask Me Everything About Programming.