December 2005
Beginner to intermediate
618 pages
20h 19m
English
cos
Calculates the cosine of an angle
#include <math.h> doublecos( doublex); doublecosf( floatx); (C99) doublecosl( long doublex); (C99)
The cos() function returns
the cosine of its argument, which is an angle measure in radians.
The return value is in the range -1 ≤ cos(x) ≤ 1.
/* * Calculate the sloping width of a roof * given the horizontal width * and the angle from the horizontal. */ #define PI 3.141593 #define DEG_PER_RAD (180.0/PI) double roof_pitch = 20.0; // In degrees double floor_width = 30.0; // In feet, say. double roof_width = 1.0 / cos( roof_pitch / DEG_PER_RAD ) * floor_width; printf( "The sloping width of the roof is %4.2f ft.\n", roof_width );
This code produces the following output:
The sloping width of the roof is 31.93 ft.
Read now
Unlock full access