学习c语言需要什么基础 数学

写在追梦的路上
C语言的数学计算库
C语言提供了一个支持数学运算的丰富的函数库,包括三角函数、双曲函数、指数和对数函数、幂函数、就近取整函数、绝对值函数和取余函数。这些函数的原型都定义在头文件&math.h&中。使用它们,需要用#include指令包含这个头文件。在利用gcc编译时,需要手动链接数学计算库,即在生成目标后添加-L. -lm选项,其形式为:
gcc -o 目标名 ... _L -lm
&math.h&中的函数可能会产生两类错误,一类是定义域错误,即函数的实参超过了函数的定义域,一类是取值范围错误,即函数的返回值超出了double类型的值范围。&math.h&中的函数的错误处理方式与其他库函数不同,当出现定义域错误时,将EDOM存储到在头文件&errno.h&声明的名字为errno的特定变量中,返回值由实现决定(有的返回NAN),当出现取值范围错误时,如果是过大,将ERANGE存储到errno中,返回正的或负的HUGE_VAL值(该宏在&math.h&中定义,如果过小,有些实现也将ERANGE存入errno,并返回0.
三角函数包括求正弦、余弦、正切、反正弦、反余弦、反正切函数,其函数原型如下:
double sin(double x);
double cos(double x);
double tan(double x);
double asin(double x);
double acos(double x);
double atan(double x);
double atan2(double y, double x);
其中sin、cos和tan函数的输入参数都是以弧度表示的,atan2函数是求y/x的反正切值。
双曲函数包括双曲余弦函数、双曲正弦函数和双曲正切函数,其函数原型分别为:
double cosh(double x);
double sinh(double x);
double tanh(double x);
三个函数的参数是以弧度为单位的。
指数函数和对数函数
指数函数和对数函数的原型为:
double exp(double x);
double log(double x);
double log10(double x);
log是求以e为底的对数,log10是求以10为底的对数。除了以上直接求指数和对数的函数外,还提供了其他三个函数,其中frexp将一个double类型的值拆分为小数和指数两部分,函数返回小数部分,并将指数部分通过其第二个参数返回,其原型为:
double frexp(double value, int *exp);
ldexp函数相反,将小数和指数部分组合为一个doubl e类型的数,其原型为:
double ldexp(double x, int exp);
还有一个函数modf将一个double类型拆分为整数和小数部分,小数部分返回,正数部分通过第二个参数返回,其原型为:
double modf(double value, double *iptr);
幂函数包括一下两种:
double pow(double x, double y);
double sqrt(double x);
pow用以计算x的y次幂,sqrt计算x的平方根。
就近取整函数、绝对值函数和取余函数
就近取整函数ceil、floor,绝对值函数fabs和取余函数fmod的原型为:
double ceil(double x);
double fabs(double x);
double floor(double x);
double fmod(double x, double y);
ceil函数计算的是大于或等于x的最小整数,floor函数计算的是小于或等于x的最大整数。fabs计算x的绝对值,fmod计算x除以y所得的余数。
#include &stdio.h&
#include &math.h&
#include &errno.h&
#define PI 3.1415926
int main()
printf("sin(PI/2) = %g\n", sin(PI/2));
printf("cos(PI/2) = %g\n", cos(PI/2));
printf("tan(PI/2) = %g\n", tan(PI/2));
if (errno == ERANGE)
printf("tan(PI/2)出现取值范围错误!\n");
printf("tan(PI/4) = %g\n", tan(PI/4));
printf("asin(1.0) = %g\n", asin(1.0));
printf("acos(1.0) = %g\n", acos(1.0));
printf("atan(1.0) = %g\n", atan(1.0));
printf("atan2(5.0,5.0) = %g\n", atan2(5.0, 5.0));
printf("cosh(PI/4) = %g\n", cosh(PI/4));
printf("sinh(PI/4) = %g\n", sinh(PI/4));
printf("tanh(PI/4) = %g\n", tanh(PI/4));
double temp = exp(5.2);
printf("exp(5.2) = %g\n", temp);
printf("log(temp) = %g\n", log(temp));
printf("log10(1000) = %g\n", log10(1000));
temp = 12.34;
int iExp = 0;
double fraction = 0.0;
fraction = frexp(temp, &iExp);
printf("%g的小数部分%g,指数部分%d\n", temp, fraction, iExp);
temp = ldexp(fraction, iExp);
printf("小数部分%g,指数部分%d组合为%g\n", fraction, iExp, temp);
double intPart = 0.0;
fraction = modf(temp, &intPart);
printf("%g的整数部分为%g,小数部分为%g\n", temp, intPart, fraction);
printf("pow(10.0, 2) = %g\n", pow(10.0, 2));
printf("sqrt(16.0) = %g\n", sqrt(16.0));
printf("ceil(12.34) = %g\n", ceil(12.34));
printf("floor(12.34) = %g\n", floor(12.34));
printf("fabs(-12.34) = %g\n", fabs(-12.34));
printf("fmod(5.5, 2.2) = %g\n", fmod(5.5, 2.2));
K.N. King 著,吕秀峰 译. C语言程序设计-现代方法. 人民邮电出版社
没有更多推荐了,
加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!当前位置: >
要用C语言表示数学关系式a&b&c,正确的表达式是()。
A.a&=b&=c&
B.(a&=b)&(b&=c)
C.(a&=b)||(b&=c)
D.(a&=b)&&(b&=c)
所属学科:
试题类型:客观题
所属知识点:
试题分数:1.0 分
暂未组卷。
暂无学习笔记。
&&&&&&&&&&&&&&&希赛网 版权所有 & &&您(@)目前可用积分:3512540跟帖回复
共获得打赏:
凯迪微信公众号扫描二维码关注发现信息价值
微信扫一扫
分享此帖文
有启发就赞赏一下
优秀帖文推荐
| 只看此人
| 不看此人
9:29:04 &&
&&&&从所给条件分析,该数是一奇数,且是63的N倍。&&&&N是奇数,但不会是5。&&&&只能是3、7、9,进一步计算得N=7,&&&&即该数为441。
| 只看此人
| 不看此人
14:29:17 &&
| 只看此人
| 不看此人
14:49:53 &&
个位数是1,且是63的倍数,又不能是6的倍数,441,35721...
此贴已经被作者于
15:53:11 编辑过
| 只看此人
| 不看此人
16:37:51 &&
用推理的方法解的一个典型的数学题:一个六位数(abcdef),分别×2、×3、×4、×5、×6,得5个六位数,且这5个六位数都是由(a、b、c、d、e、f)这6个数字组成。
跳转论坛至:
╋猫论天下&&├猫眼看人&&├商业创富&&├时局深度&&├经济风云&&├文化散论&&├原创评论&&├中间地带&&├以案说法&&├股市泛舟&&├会员阅读&&├舆情观察&&├史海钩沉╋生活资讯&&├杂货讨论&&├健康社会&&├家长里短&&├吃喝玩乐&&├职场生涯&&├咱们女人&&├家有宝宝&&├消费观察&&├房产家居&&├车友评车&&├猫眼鉴宝╋影音娱乐&&├图画人生&&├猫影无忌&&├影视评论&&├音乐之声&&├网友风采&&├娱乐八卦&&├笑话人生&&├游戏天地╋文化广场&&├菁菁校园&&├甜蜜旅程&&├心灵驿站&&├原创文学&&├汉诗随笔&&├闲话国粹&&├体育观察&&├开心科普&&├IT 数码╋地方频道&&├会馆工作讨论区&&├江西会馆&&├凯迪西南&&├海南会馆&&├珠三角&&├凯迪深圳&&├北京会馆&&├上海会馆&&├河南会馆&&├长三角&&├贵州会馆&&├杭州会馆&&├香港会馆&&├台湾会馆&&├美洲会馆╋凯迪重庆╋站务&&├站务专区&&├企业家园&&├十大美帖&&├视频创作&&├商品发布
快速回复:[原创]从一道趣味数学题说起(C语言编程实例)
本站声明:本站BBS互动社区的文章由网友自行帖上,文责自负,对于网友的贴文本站均未主动予以提供、组织或修改;本站对网友所发布未经确证的商业宣传信息、广告信息、要约、要约邀请、承诺以及其他文字表述的真实性、准确性、合法性等不作任何担保和确认。因此本站对于网友发布的信息内容不承担任何责任,网友间的任何交易行为与本站无涉。任何网络媒体或传统媒体如需刊用转帖转载,必须注明来源及其原创作者。特此声明!
【管理员特别提醒】 发布信息时请注意首先阅读 ( 琼B2- ):
;。谢谢!&>&C语言中的一些数学函数
C语言中的一些数学函数
上传大小:4KB
描叙了一些常用函数,如求绝对值函数的调用,e的x次方等等
综合评分:5
{%username%}回复{%com_username%}{%time%}\
/*点击出现回复框*/
$(".respond_btn").on("click", function (e) {
$(this).parents(".rightLi").children(".respond_box").show();
e.stopPropagation();
$(".cancel_res").on("click", function (e) {
$(this).parents(".res_b").siblings(".res_area").val("");
$(this).parents(".respond_box").hide();
e.stopPropagation();
/*删除评论*/
$(".del_comment_c").on("click", function (e) {
var id = $(e.target).attr("id");
$.getJSON('/index.php/comment/do_invalid/' + id,
function (data) {
if (data.succ == 1) {
$(e.target).parents(".conLi").remove();
alert(data.msg);
$(".res_btn").click(function (e) {
var parentWrap = $(this).parents(".respond_box"),
q = parentWrap.find(".form1").serializeArray(),
resStr = $.trim(parentWrap.find(".res_area_r").val());
console.log(q);
//var res_area_r = $.trim($(".res_area_r").val());
if (resStr == '') {
$(".res_text").css({color: "red"});
$.post("/index.php/comment/do_comment_reply/", q,
function (data) {
if (data.succ == 1) {
var $target,
evt = e || window.
$target = $(evt.target || evt.srcElement);
var $dd = $target.parents('dd');
var $wrapReply = $dd.find('.respond_box');
console.log($wrapReply);
//var mess = $(".res_area_r").val();
var mess = resS
var str = str.replace(/{%header%}/g, data.header)
.replace(/{%href%}/g, 'http://' + window.location.host + '/user/' + data.username)
.replace(/{%username%}/g, data.username)
.replace(/{%com_username%}/g, data.com_username)
.replace(/{%time%}/g, data.time)
.replace(/{%id%}/g, data.id)
.replace(/{%mess%}/g, mess);
$dd.after(str);
$(".respond_box").hide();
$(".res_area_r").val("");
$(".res_area").val("");
$wrapReply.hide();
alert(data.msg);
}, "json");
/*删除回复*/
$(".rightLi").on("click", '.del_comment_r', function (e) {
var id = $(e.target).attr("id");
$.getJSON('/index.php/comment/do_comment_del/' + id,
function (data) {
if (data.succ == 1) {
$(e.target).parent().parent().parent().parent().parent().remove();
$(e.target).parents('.res_list').remove()
alert(data.msg);
//填充回复
function KeyP(v) {
var parentWrap = $(v).parents(".respond_box");
parentWrap.find(".res_area_r").val($.trim(parentWrap.find(".res_area").val()));
评论共有1条
挺全的,呵呵
VIP会员动态
CSDN下载频道资源及相关规则调整公告V11.10
下载频道用户反馈专区
下载频道积分规则调整V1710.18
spring mvc+mybatis+mysql+maven+bootstrap 整合实现增删查改简单实例.zip
资源所需积分/C币
当前拥有积分
当前拥有C币
输入下载码
为了良好体验,不建议使用迅雷下载
C语言中的一些数学函数
会员到期时间:
剩余下载个数:
剩余积分:0
为了良好体验,不建议使用迅雷下载
积分不足!
资源所需积分/C币
当前拥有积分
您可以选择
程序员的必选
绿色安全资源
资源所需积分/C币
当前拥有积分
当前拥有C币
为了良好体验,不建议使用迅雷下载
资源所需积分/C币
当前拥有积分
当前拥有C币
为了良好体验,不建议使用迅雷下载
资源所需积分/C币
当前拥有积分
当前拥有C币
您的积分不足,将扣除 10 C币
为了良好体验,不建议使用迅雷下载
无法举报自己的资源
你当前的下载分为234。
你还不是VIP会员
开通VIP会员权限,免积分下载
你下载资源过于频繁,请输入验证码
您因违反CSDN下载频道规则而被锁定帐户,如有疑问,请联络:!
若举报审核通过,可返还被扣除的积分
被举报人:
举报的资源分:
请选择类型
资源无法下载 ( 404页面、下载失败、资源本身问题)
资源无法使用 (文件损坏、内容缺失、题文不符)
侵犯版权资源 (侵犯公司或个人版权)
虚假资源 (恶意欺诈、刷分资源)
含色情、危害国家安全内容
含广告、木马病毒资源
*详细原因:
C语言中的一些数学函数C语言数学函数大全『数学天地泛学科博客文章』
|&&|&&|&&|&&|&&|&&|&&|&&|&&|&&|&&|&&|
您现在的位置:&&>>&&>>&&>>&数学正文
网 站 搜 索
推 荐 信 息
热 门 信 息
  C语言数学函数大全
&&&&&&&&&&
C语言数学函数大全
∷∷ 中国大学https://www.unjs.com 作者:kk之家  ∷∷
函数名: labs 用 法: long labs(long n); 程序例:
#include #include
int main(void) {
long x = -L;
result= labs(x); printf(&number: %ld abs value: %ld\n&, x, result);
return 0; }
函数名: ldexp 功 能: 计算value*2的幂 用 法: double ldexp(double value, int exp); 程序例:
#include #include
int main(void) {
double x = 2;
/* ldexp raises 2 by a power of 3 then multiplies the result by 2 */ value = ldexp(x,3); printf(&The ldexp value is: %lf\n&, value);
return 0; }
函数名: ldiv 功 能: 两个长整型数相除, 返回商和余数 用 法: ldiv_t ldiv(long lnumer, long ldenom); 程序例:
/* ldiv example */
#include #include
int main(void) { ldiv_
lx = ldiv(100000L, 30000L); printf(&100000 div 30000 = %ld remainder %ld\n&, lx.quot, lx.rem); return 0; }
函数名: lfind 功 能: 执行线性搜索 用 法: void *lfind(void *key, void *base, int *nelem, int width, int (*fcmp)()); 程序例:
#include #include
int compare(int *x, int *y) { return( *x - *y ); }
int main(void) { int array[5] = {35, 87, 46, 99, 12}; size_t nelem = 5;
key = 99; result = lfind(&key, array, &nelem, sizeof(int), (int(*)(const void *,const void *))compare); if (result) printf(&Number %d found\n&,key); else printf(&Number %d not found\n&,key);
return 0; }
函数名: line 功 能: 在指定两点间画一直线 用 法: void far line(int x0, int y0, int x1, int y1); 程序例:
#include #include #include #include
int main(void) { /* request auto detection */ int gdriver = DETECT, gmode, int xmax,
/* initialize graphics and local variables */ initgraph(&gdriver, &gmode, &&);
/* read result of initialization */ errorcode = graphresult(); /* an error occurred */ if (errorcode != grOk) { printf(&Graphics error: %s\n&, grapherrormsg(errorcode)); printf(&Press any key to halt:&); getch(); exit(1); }
setcolor(getmaxcolor()); xmax = getmaxx(); ymax = getmaxy();
/* draw a diagonal line */ line(0, 0, xmax, ymax);
/* clean up */ getch(); closegraph(); return 0; }
函数名: linerel 功 能: 从当前位置点(CP)到与CP有一给定相对距离的点画一直线 用 法: void far linerel(int dx, int dy); 程序例:
#include #include #include #include
int main(void) { /* request auto detection */ int gdriver = DETECT, gmode, char msg[80];
/* initialize graphics and local variables */ initgraph(&gdriver, &gmode, &&);
/* read result of initialization */ errorcode = graphresult(); if (errorcode != grOk) { printf(&Graphics error: %s\n&, grapherrormsg(errorcode)); printf(&Press any key to halt:&); getch(); exit(1); }
/* move the C.P. to location (20, 30) */ moveto(20, 30);
/* create and output a message at (20, 30) */ sprintf(msg, & (%d, %d)&, getx(), gety()); outtextxy(20, 30, msg);
/* draw a line to a point a relative distance away from the current value of C.P. */ linerel(100, 100);
/* create and output a message at C.P. */ sprintf(msg, & (%d, %d)&, getx(), gety()); outtext(msg);
/* clean up */ getch(); closegraph(); return 0; }
函数名: localtime 功 能: 把日期和时间转变为结构 用 法: struct tm *localtime(long *clock); 程序例:
#include #include #include
int main(void) { time_ struct tm *
/* gets time of day */ timer = time(NULL);
/* converts date/time to a structure */ tblock = localtime(&timer);
printf(&Local time is: %s&, asctime(tblock));
return 0; }
函数名: lock 功 能: 设置文件共享锁 用 法: int lock(int handle, long offset, long length); 程序例:
#include #include #include #include #include #include
int main(void) { int handle,
/* Must have DOS Share.exe loaded for */ /* file locking to function properly */
handle = sopen(&c:\\autoexec.bat&, O_RDONLY,SH_DENYNO,S_IREAD);
if (handle & 0) { printf(&sopen failed\n&); exit(1); }
length = filelength(handle); status = lock(handle,0L,length/2);
if (status == 0) printf(&lock succeeded\n&); else printf(&lock failed\n&);
status = unlock(handle,0L,length/2);
if (status == 0) printf(&unlock succeeded\n&); else printf(&unlock failed\n&);
close(handle); return 0; }
函数名: log 功 能: 对数函数ln(x) 用 法: double log(double x); 程序例:
#include #include
int main(void) {
double x = 8.6872;
result = log(x); printf(&The natural log of %lf is %lf\n&, x, result);
return 0; }
函数名: log10 功 能: 对数函数log 用 法: double log10(double x); 程序例:
#include #include
int main(void) {
double x = 800.6872;
result = log10(x); printf(&The common log of %lf is %lf\n&, x, result);
return 0; }
函数名: longjump 功 能: 执行非局部转移 用 法: void longjump(jmp_buf env, int val); 程序例:
#include #include #include
void subroutine(jmp_buf);
int main(void) {
value = setjmp(jumper); if (value != 0) { printf(&Longjmp with value %d\n&, value); exit(value); } printf(&About to call subroutine ... \n&); subroutine(jumper);
return 0; }
void subroutine(jmp_buf jumper) { longjmp(jumper,1); }
函数名: lowvideo 功 能: 选择低亮度字符 用 法: void lowvideo(void); 程序例:
int main(void) { clrscr();
highvideo(); cprintf(&High Intesity Text\r\n&); lowvideo(); gotoxy(1,2); cprintf(&Low Intensity Text\r\n&);
return 0; }
函数名: lrotl, _lrotl 功 能: 将无符号长整型数向左循环移位 用 法: unsigned long lrotl(unsigned long lvalue, int count); unsigned long _lrotl(unsigned long lvalue, int count); 程序例:
/* lrotl example */ #include #include
int main(void) {
unsigned long value = 100;
result = _lrotl(value,1); printf(&The value %lu rotated left one bit is: %lu\n&, value, result);
return 0; }
函数名: lsearch 功 能: 线性搜索 用 法: void *lsearch(const void *key, void *base, size_t *nelem, size_t width, int (*fcmp)(const void *, const void *)); 程序例:
#include #include
int compare(int *x, int *y) { return( *x - *y ); }
int main(void) { int array[5] = {35, 87, 46, 99, 12}; size_t nelem = 5;
key = 99; result = lfind(&key, array, &nelem, sizeof(int), (int(*)(const void *,const void *))compare); if (result) printf(&Number %d found\n&,key); else printf(&Number %d not found\n&,key);
return 0; }
函数名: lseek 功 能: 移动文件读/写指针 用 法: long lseek(int handle, long offset, int fromwhere); 程序例:
#include #include #include #include #include
int main(void) {
char msg[] = &This is a test&;
/* create a file */ handle = open(&TEST.$$$&, O_CREAT | O_RDWR, S_IREAD | S_IWRITE);
/* write some data to the file */ write(handle, msg, strlen(msg));
/* seek to the begining of the file */ lseek(handle, 0L, SEEK_SET);
/* reads chars from the file until we hit EOF */ do { read(handle, &ch, 1); printf(&%c&, ch); } while (!eof(handle));
close(handle); return 0; }
上一篇数学:
下一篇数学:
【声明:本站所发表的全部或部分内容仅代表个人观点,与本站无关,谢谢合作!】
  广而告之
特别感谢西部数码提供本站空间!版权所有 Copyright&
中国大学中华人民共和国网站备案号/经营许可证号:
本站部分内容来自互联网,如有侵权,请告知站长为谢!不良信息,欢迎举报!

我要回帖

更多关于 c语言正确的函数声明 的文章

 

随机推荐