1. 1、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
function1

the c programming language----Guangdong University of Technology 求一元二次方程ax2+bx+c=0的解(a≠0)。 /*案例代码文件名:AL4_6.C。*/ /*功能:求一元二次方程的解。*/ #include math.h main() {float a,b,c,disc,x1,x2,p,q; scanf(“%f,%f,%f”, a, b, c); disc=b*b-4*a*c; if (fabs(disc)=1e-6) /*fabs():求绝对值库函数*/ printf(“x1=x2=%7.2f\n”, -b/(2*a)); /*输出两个相等的实根*/ else { if (disc1e-6) {x1=(-b+sqrt(disc))/(2*a); /*求出两个不相等的实根*/ x2=(-b-sqrt(disc))/(2*a); printf(x1=%7.2f,x2=%7.2f\n, x1, x2); } else {p=-b/(2*a); /*求出两个共轭复根*/ q=sqrt(fabs(disc))/(2*a); printf(“x1=%7.2f + %7.2f i\n“, p, q); /*输出两个共轭复根*/ printf(”x2=%7.2f - %7.2f i\n“, p, q); } } } [程序演示] 说明:由于实数在计算机中存储时,经常会有一些微小误差,所以本案例判断disc是否为0的方法是:判断disc的绝对值是否小于一个很小的数(例如10-6)。 思考题:如果将系数a、b、c定义成整数,能否直接判断disc是否等于0? why modularize? 为什么要模块化 how many lines could you read without pains? how many lines can be putted into function main()? how the teamwork goes if all the source code are putted into the function main()? benefits of Modularization modules would do its own work each module(模块) only pay attention to doing one thing easy to design,code,debug(排除故障),test and maintain modules integrated developers would do their own work assign task by modules, responsibility is clear develop parallel,shorten the time divide and rule(分而治之) details hidden functions all C programs are made of functions library function: ANSI C’s standard lib functions all ANSI C compilers will proved these std libs these function are all accord with ANSI C std lib functions provided by manufacturers user function: functions we right of our own we can package them to a lib for other ones definition function is some kind of a operation: it’s name tell the operation regulation it’s parameters are the operands it’s return value means the result of the operation. function will stop when meeting the return statement or },the program continues from the point

文档评论(0)

sh4125733 + 关注
实名认证
内容提供者

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

1亿VIP精品文档

相关文档