C语言程序设计-sin()和COS()

1.

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	", x[i]);
	}
	printf("
");
}

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);
}
经验分享 程序员 微信小程序 职场和发展