1. C 标准库 - <math.h>
C 库函数 double sin(double x) 返回弧度角 x 的正弦
声明
下面是 sin() 函数的声明。
double sin(double x)
返回值
该函数返回 x 的正弦
实例
下面的实例演示了 sin() 和COS()函数的用法。
#include <stdio.h>
#include <math.h>
// 正弦函数的声明
double sin(double);
double cos(double);
#define PI 3.14159265
double pingfang(double x)
{
return x*x;
}
void transform(double a[], double b[], int len, double (*p)(double))
{
int i;
double val = PI / 180;//获取弧度角
for(i=0; i<len; i++)
{
b[i] = (*p)(a[i]*val);//返回弧度角 x 的正余弦弦
//b[i] = ( p)(a[i]*val);
//b[i] = p (a[i]*val);
}
}
void show(double x[], int len)
{
int i;
for(i=0; i<len; i++)
{
printf("%lf\t", x[i]);
}
printf("\n");
}
int main(void)
{
double a[4] ={45,2,3,4};
double b[4];
transform(a, b, 4, sin);
show(b, 4);
transform(a, b, 4, cos);
show(b, 4);
transform(a, b, 4, pingfang);
show(b, 4);
}