《计算导论与程序设计》课程教学资源(PPT课件讲稿)Chap 5 函数

chap5函数 51计算圆柱体积 52数字金字塔 53复数运算
Chap 5 函数 5.1 计算圆柱体积 5.2 数字金字塔 5.3 复数运算

本章要点 ■函数的作用?如何确定函数功能? 怎样定义函数?如何调用函数?定义函数与声 明函数有何区别? ■什么是函数的参数?怎样确定函数的参数? ■在函数调用时,参数是如何传递数据的? ■变量与函数有什么关系?如何使用局部变量和 全局变量? ■什么是静态变量?
本章要点 ◼ 函数的作用?如何确定函数功能? ◼ 怎样定义函数?如何调用函数?定义函数与声 明函数有何区别? ◼ 什么是函数的参数?怎样确定函数的参数? ◼ 在函数调用时,参数是如何传递数据的? ◼ 变量与函数有什么关系?如何使用局部变量和 全局变量? ◼ 什么是静态变量?

51计算圆柱体积 ■511程序解析 512函数的定义 513函数的调用 ■5.14函数程序设计
5.1 计算圆柱体积 ◼ 5.1.1 程序解析 ◼ 5.1.2 函数的定义 ◼ 5.1.3 函数的调用 ◼ 5.1.4 函数程序设计

51.1程序解析一计算圆柱体积 例5-1输入圆柱体的高和半径,求圆柱体积, Vo|ume=T*r2h。 要求定义和调用函数 cylinder(rh)计算圆 柱体的体积
5.1.1 程序解析-计算圆柱体积 例5-1 输入圆柱体的高和半径,求圆柱体积, volume=π*r2 *h。 要求定义和调用函数cylinder (r, h )计算圆 柱体的体积

/计算圆柱体积* 例5-1源程序 include int main( void) double height, radius, volume double cylinder( double r, double h);/函数声明 printf (" enter radius and height: scanf(%lf%If", &radius, &height); /调用函数,返回值赋给 volume volume cylinder (radius, height ) printf Volume =%.3fIn", volume) return 0
/* 计算圆柱体积 */ 例5-1源程序 #include int main( void ) { double height, radius, volume; double cylinder (double r, double h); /* 函数声明*/ printf ("Enter radius and height: "); scanf ("%lf%lf", &radius, &height); /* 调用函数,返回值赋给volume */ volume = cylinder (radius, height ); printf ("Volume = %.3f\n", volume); return 0; }

例5-1源程序 Enter radius and height:3010 Volume 282743 定义求圆柱体积的函数* double cylinder(double r, double h) double result e result=31415926*r*r*h;/计算体积* return result 返回结果
例5-1源程序 /* 定义求圆柱体积的函数 */ double cylinder (double r, double h) { double result; result =3.1415926 * r * r * h; /* 计算体积 */ return result; /* 返回结果 */ } Enter radius and height: 3.0 10 Volume = 282.743

include 例 Enter radius and height: 3.0 10 int main( void) Vo|ume=282743 double height, radius, volume double cylinder( double r, double h);/函数声明 printf ("Enter radius and height: scanf(%lf%If ,&radius, &height) vo|ume= cylinder(radius, height);问题: prn("oume=%3m", volume)}函数是如何运行的? return o double cylinder(double r, double h) double result. result =3, 1415926*r*r* h: return result
#include int main( void ) 例5-1源程序 { double height, radius, volume; double cylinder (double r, double h); /* 函数声明*/ printf ("Enter radius and height: "); scanf ("%lf%lf", &radius, &height); volume = cylinder (radius, height ); printf ("Volume = %.3f\n", volume); return 0; } double cylinder (double r, double h) { double result; result =3.1415926 * r * r * h; return result; } Enter radius and height: 3.0 10 Volume = 282.743 问题: 函数是如何运行的?

512函数的定义 函数是指完成一个特定工作的独立程序模块 口库函数:由C语言系统提供定义 如 scanf()、 printf(等函数 口自定义函数:需要用户自己定义 如计算圆柱体体积函数 cylinder() man(也是一个函数,C程序由一个main0或多个 函数构成。 ■程序中一旦调用了某个函数,该函数就会完成特定 的计算,然后返回到调用它的地方 口函数经过运算,得到一个明确的运算结果,并需要回送 该结果。例如,函数 cylinder(返回圆柱的体积
5.1.2 函数的定义 ◼ 函数是指完成一个特定工作的独立程序模块。 库函数:由C语言系统提供定义 如scanf()、printf()等函数 自定义函数:需要用户自己定义 如计算圆柱体体积函数cylinder() ◼ main()也是一个函数,C程序由一个main()或多个 函数构成。 ◼ 程序中一旦调用了某个函数,该函数就会完成特定 的计算,然后返回到调用它的地方。 函数经过运算,得到一个明确的运算结果,并需要回送 该结果。例如,函数cylinder()返回圆柱的体积

double cylinder(double r, double h) i double result resu|t=3.1415926*r*r*h: 512函数定义 return result. 函数返回值的类型 没有分号 函数类型函数名(形参表)P函数首部 函数体* 函数实现过程 return表达式; 只能返回一个值 把函数运算的结果回送给主函数
5.1.2 函数定义 函数类型 函数名(形参表) /* 函数首部 */ { /* 函数体 */ 函数实现过程 return 表达式; } 把函数运算的结果回送给主函数 只能返回一个值 函数返回值的类型 没有分号 double cylinder (double r, double h) { double result; result = 3.1415926 * r * r * h; return result; }

分析函数的定义 函数类型函数名形参表 double cylinder( double r, double h)函数首部* /函数体,写在一对大括号内* double result. result=31415926*r*r*h;/计算圆柱体积* return result: 返回运算结果 与函数类型一致
double cylinder (double r, double h) /* 函数首部 */ { /* 函数体,写在一对大括号内 */ double result; result =3.1415926 * r * r * h; /* 计算圆柱体积 */ return result; /* 返回运算结果*/ } 分析函数的定义 函数类型 函数名 形参表 与函数类型一致
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 贵州大学:计算机应用基础(PPT课件讲稿)计算机基础知识.pdf
- 《计算机组装与维护》课程教学资源(PPT课件讲稿)第十一章 计算机数据恢复技术.ppt
- 《C语言程序设计》课程教学资源(PPT讲稿)第1章 程序设计和C语言.pptx
- 北京师范大学:《计算机文化基础》课程教学资源(PPT课件讲稿)08 网页制作基础知识(赵国庆).ppt
- 水平集方法与图像分割 Level set method and image segmentation.pptx
- 《计算机网络》课程教学资源(PPT讲稿)网络安全(访问控制、加密、防火墙).ppt
- 同济大学:《大数据分析与数据挖掘 Big Data Analysis and Mining》课程教学资源(PPT课件讲稿)Platforms for Big Data Mining(主讲:饶卫雄).ppt
- 《数据结构》课程教学资源(PPT课件讲稿)第八章 图.ppt
- 《单片机应用技术》课程PPT教学课件(C语言版)第3章 MCS-51指令系统及汇编程序设计.ppt
- 《编译原理与技术》课程教学资源(PPT课件讲稿)代码优化.ppt
- Progress of Concurrent Objects with Partial Methods.pptx
- 《网络搜索和挖掘关键技术 Web Search and Mining》课程教学资源(PPT讲稿)Lecture 12 Language Models.ppt
- 四川大学:《操作系统 Operating System》课程教学资源(PPT课件讲稿)Chapter 6 Concurrency - Deadlock(死锁)and Starvation(饥饿).ppt
- 《操作系统》课程教学资源(PPT课件讲稿)实时调度 Real-Time Scheduling.ppt
- 白城师范学院:《数据库系统概论 An Introduction to Database System》课程教学资源(PPT课件讲稿)第二章 关系数据库(2.1-2.3).ppt
- 《计算机算法设计与分析》课程教学资源(PPT课件)第8章回溯法.ppt
- 清华大学出版社:《计算机应用基础实例教程》课程教学资源(PPT课件讲稿,第二版,共七章,主编:吴霞,制作:李晓新).ppt
- 中国科学技术大学:《计算机体系结构》课程教学资源(PPT课件讲稿)绪论、第1章 量化设计与分析基础(主讲:周学海).ppt
- 北京大学:烟花算法的变异算子(PPT讲稿)Mutation Operators of Fireworks Algorithm.pptx
- Introduction to Text Mining 文本挖掘.pptx
- 《计算机网络 Computer Networking》课程教学资源(PPT课件讲稿)Chapter 08 Network Security.ppt
- 《计算机网络与通信》课程教学资源(PPT课件)Chapter 8 传输层.ppt
- 《数据结构与算法分析》课程教学资源(PPT讲稿)Lists, Stacks and Queues.ppt
- 沈阳理工大学:《Visual Basic 6.0程序设计》课程教学资源(PPT课件讲稿)第三章 VB基本语言.ppt
- 南京大学:《计算机网络 Computer Networks》课程教学资源(PPT课件讲稿)简介、第一章 引论(谭晓阳).ppt
- 中国科学技术大学:《Linux操作系统分析》课程教学资源(PPT课件讲稿)第一章 绪论(主讲:陈香兰).ppt
- 西华大学:《电子商务概论》课程教学资源(PPT课件讲稿)第4章 电子商务的安全问题.ppt
- 北京大学:未来互联网体系结构(PPT讲稿)Future Internet Architecture(Introduction).pptx
- 《计算机组成原理》课程教学资源(PPT课件讲稿)第5章 输入输出系统.ppt
- 清华大学出版社:《物流电子商务》课程教学资源(PPT课件讲稿,共八章,主编:董铁,制作:李晓新).ppt
- 电子工业出版社:《计算机网络》课程教学资源(第五版,PPT课件讲稿)第三章 数据链路层.ppt
- 电子工业出版社:《计算机网络》课程教学资源(第五版,PPT课件讲稿)第四章 网络层.ppt
- 南京大学:《面向对象技术 OOT》课程教学资源(PPT课件讲稿)契约式设计 Design by Contract.ppt
- 《计算机网络安全》课程教学资源(PPT课件讲稿)第三章 网络防病毒.ppt
- 同济大学:《软件测试》课程教学资源(PPT课件讲稿)第5章 单元测试(朱少民).ppt
- 香港科技大学:Information-Agnostic Flow Scheduling for Commodity Data Centers.pptx
- 南京航空航天大学:《数据结构》课程教学资源(PPT课件讲稿)第九章 查找.ppt
- 《数字图像处理 Digital Image Processing》课程教学资源(PPT课件讲稿)第10章数字图像处理的应用.ppt
- 北京大学信息学院:《高级软件工程》课程教学资源(PPT课件讲稿)第五讲 新运行平台——云计算平台.pptx
- 视觉系统(PPT课件讲稿)The Visual System.ppt