如何通過C/C++求任意角度的餘弦值
阿新 • • 發佈:2021-02-07
技術標籤:Are You OKay C/C++c++c語言程式人生經驗分享
題目描述
圓周率為3.1415926,求45度、90度的餘弦值
詳細C++程式碼如下:
#include<iostream>
#include<math.h>
#include<conio.h>
using namespace std;
int main()
{
float x = 45.0;
float y = 90.0;
float PI = 3.1415926;
float xh = PI * x / 180.00;
float yh = PI * y / 180.00;
float cosVal = cos(xh);
printf("cos of %f is : %lf\n", x, cosVal);
cosVal = cos(yh);
printf("cos of %f is : %lf\n", y, cosVal);
getch();
return 0;
}
執行結果:
對應的C程式碼
#include <stdio.h>
#include <math.h>
#include <conio.h>
main(){
float x=45.0;
float PI=3.1415926 ;
float xh=PI*x/180.00;
float cosVal=cos(xh);
printf("cos of %f is :%lf\n",x,cosVal);
getch();
}