十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
math.h里的三角函数用的单位是弧度,你貌似错在这里。 答案补充 Example
成都创新互联自2013年创立以来,先为阿巴嘎等服务建站,阿巴嘎等地企业,进行企业商务咨询服务。为阿巴嘎企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
/* SINCOS.C: This program displays the sine, hyperbolic
* sine, cosine, and hyperbolic cosine of pi / 2.
*/
#include math.h
#include stdio.h
void main( void )
{
double pi = 3.1415926535;
double x, y;
x = pi / 2;
y = sin( x );
printf( "sin( %f ) = %f\n", x, y );
y = sinh( x );
printf( "sinh( %f ) = %f\n",x, y );
y = cos( x );
printf( "cos( %f ) = %f\n", x, y );
y = cosh( x );
printf( "cosh( %f ) = %f\n",x, y );
} 答案补充 Output
sin( 1.570796 ) = 1.000000
sinh( 1.570796 ) = 2.301299
cos( 1.570796 ) = 0.000000
cosh( 1.570796 ) = 2.509178
Parameter
x
Angle in radians
要用弧度计算的,另外,pintf语句中,应该是"%lf",不是"f%"
sin()是三角函数,参数使用的是弧度,不是度。
asin()才是反三角函数。
资料 :
NAME
asin, asinf, asinl - arc sine function
SYNOPSIS
#include math.h
double asin(double x);
float asinf(float x);
long double asinl(long double x);
Link with -lm.
DESCRIPTION
The asin() function calculates the arc sine of x; that is the value
whose sine is x. If x falls outside the range -1 to 1, asin() fails
and errno is set.
RETURN VALUE
The asin() function returns the arc sine in radians and the value is
mathematically defined to be between -PI/2 and PI/2 (inclusive).
#include stdio.h
long cube(int x)
{
return x*x*x;
}
int main()
{
int x,y;
scanf("%d%d",x,y);
printf("%d^3 + %d^3 = %ld",x,y,cube(x) + cube(y));
printf("%d^3 - %d^3 = %ld",x,y,cube(x) - cube(y));
return 0;
}
包含头文件 math.h
反3角函数有 acos(double),asin(double),atan(double),atan(double,double),
返回值 double 型,弧度值。转角度要 *180.0/3.1416
例如:
#include stdio.h
#includestdlib.h
#includemath.h
int main()
{
double x=0.5;
printf("acos=%.2lf degrees\n",acos(x) * 180.0/3.1416);
printf("asin=%.2lf degrees\n",asin(x) * 180.0/3.1416);
printf("atan=%.2lf degrees\n",atan(x) * 180.0/3.1416);
printf("atan2=%.2lf degrees\n",atan2(1.0,2.0) * 180.0/3.1416);
return 0;
}