hdu 2080 夹角有多大(弧度制)

AC代码:

#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;

int main()
{
    int t;
    double x1,x2,y1,y2,cosx,theta;
    while(cin>>t)
    {
        while(t--)
        {
            cin>>x1>>y1>>x2>>y2;    
            cosx=(x1*x2+y1*y2)*1.0/(sqrt(x1*x1+y1*y1)*sqrt(x2*x2+y2*y2));
            while(cosx<-1)cosx+=1;
            while(cosx>1)cosx-=1;
            theta=acos(cosx)/acos(-1)*180;//算出来是弧度制,需要乘180/3.14; 
            printf("%.2lf
",theta);
        }    
    }
    return 0;
}
View Code

头文件:#include <math.h>
acos() 函数返回一个以弧度表示的反余弦值,其原型为:
    double acos (double x);

【参数】x 为余弦值,范围为 -1 到 1 之间,超出此范围将会导致错误,并设置 errno 的值为 EDOM.

【返回值】返回 0 至 π 之间的计算结果,单位为弧度,在函数库中角度均以弧度来表示。

弧度与角度的关系为:
弧度 = 180 / π 角度
角度 = π / 180 弧度

  1. #include<stdio.h>
  2. #include<math.h>
  3. int main(void)
  4. {
  5. double angl,result;
  6. angl = 1;
  7. result =acos(cos(angl));/*求反余弦值*/
  8. printf("acos(%lf) is %lf ",cos(angl),result);/*格式化输出*/
  9. angl = 3.1415926;
  10. result = acos(cos(angl));/*求反余弦值*/
  11. printf("acos(%lf) is %lf ",cos(angl),result);/*格式化输出*/
  12. return 0;
  13. }

运行结果:
acos(0.540302)  is  1.000000
acos (-1.000000)  is  3.141593

原文地址:https://www.cnblogs.com/lyqf/p/10263554.html