例题
习题 1-4 《算法竞赛入门经典(第二版)》
输入正整数n(n<360),输出n度的sin、cos值
//#include<bits/stdc++.h>
//#include<stdio.h>
//与下面的不同可以参照另一文《C++ Basic Std I/O and File I/O》
#include<iostream>
using namespace std;
int main{
int n;
scanf("%d",&n);
if (n<360) {
double result = cos((n/180.0)*M_PI); //常见错误:n/180为int,而非float
printf("%0.3f",result);
}
//return 0
}
三角函数语句表
三角函数 | 语句 | Range |
---|---|---|
sin | double sin(double rand); | [-1,1] |
cos | double cos(double rand); | [-1, 1] |
tan | double tan(double rand); | [-inf,inf] |
asin | double asin(double rand); | [-PI/2,PI/2] |
acos | double acos(double rand); | [0,PI] |
atan | double atan(double rand); | [-PI/2,PI/2] |
pi | M_PI | pi |