第1关:x的余弦值
200
- 任务要求
- 参考答案
- 评论118
任务描述
本关需要你通过switch
语句的编写,完成求x
的y
值结果的小程序。详情如下:
-
当
0<=x<10
时,y
=cos(x+3.0)
; -
当
10<=x<20
时,y
=pow(cos(x+7.5),2)
; -
当
20<=x<30
时,y
=pow(cos(x+4.0),4)
。
相关知识
cos()
C
库函数double cos(double x)
返回一个弧度角x
的余弦值。
参数:
x
这是浮点值同比弧度表示的角度。
返回值:
- 这个函数返回
x
的余弦。
例如:
int main ()
{
double x, ret, val;
x = 60.0;
val = 180.0 / PI;
ret = cos( x*val );
printf("The cosine of %lf is %lf degrees
", x, ret);
x = 90.0;
val = 180.0 / PI;
ret = cos( x*val );
printf("The cosine of %lf is %lf degrees
", x, ret);
return(0);
}
运行上面的程序,将产生以下结果:
The cosine of 60.000000 is 0.664171 degrees
The cosine of 90.000000 is -0.299510 degrees
pow()
C
库函数double pow(double x, double y)
表示x
的y
次方。
例如:
{
printf("Value 8.0 ^ 3 = %lf", pow(8.0, 3));
printf("Value 3.05 ^ 1.98 = %lf", pow(3.05, 1.98));
return(0);
}
运行上面的程序,将产生以下结果:
Value 8.0 ^ 3 = 512.000000
Value 3.05 ^ 1.98 = 9.097324