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

 

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);
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值