C语言基础四:math.h的简单用法(菜鸟编程教学4).docx

C语言基础四:math.h的简单用法(菜鸟编程教学4).docx

  1. 1、本文档共3页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
我们直接举个小例子了解一下math.h这个头文件的用法! 下面我举个程序小说明一下就可以了: #include stdio.h #include math.h #include stdlib.h main() { double x,y; x = 30.00; y = 60.00; printf(\n == x = %lf\t y = %lf \n,x,y);//输出 x 与 y 的初始值 //sine of x, x in radians printf(\n == sin(x) = %lf \n,sin(x)); //cosine of x, x in radians printf(\n == cos(x) = %lf \n,cos(x)); //arctangent of y/x, in radians printf(\n == y/x = %lf \n,atan2(y,x)); //exponential function ex printf(\n == e 的 x 次方= %lf \n,exp(x)); //natural (base e) logarithm of x (x0) printf(\n == log(x) = %lf \n,log(x)); //common (base 10) logarithm of x (x0) printf(\n == log10(x) = %lf \n,log10(x)); //x^y printf(\n == x 的 y 次方 = %lf \n,pow(x,y)); //square root of x (x0) printf(\n == 根号 x = %lf \n,sqrt(x)); //absolute value of |x| printf(\n == x 的绝对值 = %lf \n,fabs(x)); getchar(); } //这里就是math.h头文件的具体用法,程序大家一看便知意思,就不加以讲解了。 //在此我们用c 顺便举个三角函数精确求法的简单例子: #includeiostream #includeiomanip #includecmath using namespace std; const double pi(3.1415926535897932384626433832795); //这里是C 一种赋值方式,不用“=”也是可以的 int main() { system(@echo off); system(title 角度计算器 By:opencTM.); system(color 3f); cout\nends==计算sin,cos,tan角度的计算器,可以精确到万亿分位!endl; cout\nsetw(61)ends----程序设计人:opencTM.endl; cout\nends==请按任意继续...\nendl; system(pause nul); system(color 5f); double a,b; cout==请输入角度:; cina; system(color 97); b=a*pi/180; cout==十进制的表示的一般准确值:\n; coutdecsetw(16)sin(a)=sin(b)endl; coutdecsetw(16)cos(a)=cos(b)endl; coutdecsetw(16)tan(a)=tan(b)endl; cout==八进制的表示的较精确值:\n; coutoctsetw(12)setprecision(8)sin(a)=sin(b)endl; coutoctsetw(12)setprecision(8)cos(a)=cos(b)endl; coutoctsetw(12)setprecision(8)tan(a)=tan(b)endl; cout==十六进制的表示的欠

文档评论(0)

勤能补拙 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档