3684 - C++作业1-4:计算数学函数式的值
从键盘输入一个角度值a,x为a对应的弧度值,编程求 y=|sin(x*x)| / (1-cos(x)) 的值。注意定义圆周率常量PI为3.141592658979.
Input
一个实数,例如180
Output
一个实数,(例如输入180,输出为0.215151)
Examples
Input
180
Output
0.215151
Hint
x=a*180/PI;需要包含cmath头文件。
Solution C
# include <stdio.h> # include <math.h> # define PI 3.141592658979 int main() { double a, x, y; scanf("%lf", &a); x = (a / 180) * PI; y = fabs(sin(x * x)) / (1 - cos(x)); printf("%lf", y); return 0; }
Solution C++
#include<iostream> using namespace std; #include<cmath> int main() { const double PI=3.14159265358979; double x,y; cin>>x; x=x*PI/180; y=abs(sin(x*x))/(1-cos(x)); cout<<y; return 0; }
Hint
x=a*180/PI;需要包含cmath头文件。