69,368
社区成员
发帖
与我相关
我的任务
分享
cos function
double cos ( double x );
float cos ( float x );
long double cos ( long double x ); <cmath>
Compute cosine
Returns the cosine of an angle of x radians.
Parameters
x
Floating point value representing an angle expressed in radians.
Return Value
Cosine of x.
Portability
In C, only the double version of this function exists with this name.
Example
/* cos example */
#include <stdio.h>
#include <math.h>
#define PI 3.14159265
int main ()
{
double param, result;
param = 60.0;
result = cos (param*PI/180);
printf ("The cosine of %lf degrees is %lf.\n", param, result );
return 0;
}
Output:
The cosine of 60.000000 degrees is 0.500000.
See also
sin Compute sine (function)
tan Compute tangent (function)
double sin ( double x );
float sin ( float x );
long double sin ( long double x ); <cmath>
Compute sine
Returns the sine of an angle of x radians.
Parameters
x
Floating point value representing an angle expressed in radians.
Return Value
Sine of x.
Portability
In C, only the double version of this function exists with this name.
Example
/* sin example */
#include <stdio.h>
#include <math.h>
#define PI 3.14159265
int main ()
{
double param, result;
param = 30.0;
result = sin (param*PI/180);
printf ("The sine of %lf degrees is %lf.\n", param, result );
return 0;
}
Output:
The sine of 30.000000 degrees is 0.500000.
See also
cos Compute cosine (function)
tan Compute tangent (function)
#include <stdio.h>
double sin_map[20] =
{0.841471, 0.909297, 0.14112, -0.756802, -0.958924,
-0.279415, 0.656987, 0.989358, 0.412118, -0.544021,
-0.99999, -0.536573, 0.420167, 0.990607, 0.650288,
-0.287903, -0.961397, -0.750987, 0.149877, 0.912945};
double cos_map[20] =
{0.540302, -0.416147, -0.989992, -0.653644, 0.283662,
0.96017, 0.753902, -0.1455, -0.91113, -0.839072,
0.0044257, 0.843854, 0.907447, 0.136737, -0.759688,
-0.957659, -0.275163, 0.660317, 0.988705, 0.408082};
inline double sin(int x) {return sin_map[x-1];}
inline double cos(int x) {return cos_map[x-1];}
int main()
{
double max = 1-sin(1)-cos(1);
double f;
for(int x=2; x<=20; ++x) {
f=x-sin(x)- cos(x);
if(max < f) max=f;
}
printf("MAX = %f\n", max);
}