如何通过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();
}

之后我会持续更新,如果喜欢我的文章,请记得一键三连哦,点赞关注收藏,你的每一个赞每一份关注每一次收藏都将是我前进路上的无限动力 !!!↖(▔▽▔)↗感谢支持!

猜你喜欢

转载自blog.csdn.net/qq_44631615/article/details/112557667