1. 程式人生 > 其它 >如何通過C/C++求任意角度的餘弦值

如何通過C/C++求任意角度的餘弦值

技術標籤: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(); }

之後我會持續更新,如果喜歡我的文章,請記得一鍵三連哦,點贊關注收藏,你的每一個贊每一份關注每一次收藏都將是我前進路上的無限動力 !!!↖(▔▽▔)↗感謝支援!