Sams Teach Yourself C in 21 Days

(singke) #1
abs() int abs(int x) Return the absolute
labs()long labs(long x)
value of their arguments.
floor() double floor(double x) Returns the largest integer not greater
than its argument. For example,
floor(4.5)returns4.0, and
floor(-4.5)returns-5.0.
modf() double modf(double x, Splitsxinto integral and fractional
double *y) parts, each with the same sign as x.
The fractional part is returned by the
function, and the integral part is
assigned to *y.
pow() double pow(double x, Returnsxy. An error occurs if x == 0
double y) andy <= 0, or if x < 0andyis not
an integer.
fmod() double fmod(double x, Returns the floating-point remainder
double y) ofx/y, with the same sign as x. The
function returns 0 ifx == 0.

A Demonstration of the Math Functions ......................................................


An entire book could be filled with programs demonstrating all of the math functions.
Listing 19.1 contains a single program that demonstrates several of these functions.

LISTING19.1 math.c. Using the C library math functions
1: /* Demonstrates some of C’s math functions */
2:
3: #include <stdio.h>
4: #include <math.h>
5:
6: int main( void )
7: {
8:
9: double x;
10:
11: printf(“Enter a number: “);
12: scanf( “%lf”, &x);
13:
14: printf(“\n\nOriginal value: %lf”, x);
15:

536 Day 19

Function Prototype Description

INPUT

30 448201x-CH19 8/13/02 11:20 AM Page 536

Free download pdf