没有合适的资源?快使用搜索试试~ 我知道了~
首页快速学习c语言How to Think Like a Computer Scientist-C Version
资源详情
资源评论
资源推荐
How to Think Like a Computer Scientist
C Version
Allen B. Downey
C-Version by Thomas Scheffler
Version 1.08
November 25th, 2012
2
Copyright (C) 1999 Allen B. Downey
This book is an Open Source Textbook (OST). Permission is granted to repro-
duce, store or transmit the text of this book by any means, electrical, mechan-
ical, or biological, in accordance with the terms of the GNU General Public
License as published by the Free Software Foundation (version 2).
This book is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
License for more details.
The original form of this book is LaTeX source code. Compiling this LaTeX
source has the effect of generating a device-independent representation of a
textbook, which can be converted to other formats and printed. All intermediate
representations (including DVI and Postscript), and all printed copies of the
textbook are also covered by the GNU General Public License.
The LaTeX source for this book, and more information about the Open Source
Textbook project, is available from
http://www.cs.colby.edu/~downey/ost
or by writing to Allen B. Downey, 5850 Mayflower Hill, Waterville, ME 04901.
The GNU General Public License is available from www.gnu.org or by writing
to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
This book was typeset by the author using LaTeX and dvips, which are both
free, open-source programs.
Contents
1 The way of the program 1
1.1 What is a programming language? . . . . . . . . . . . . . . . . . 1
1.2 What is a program? . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 What is debugging? . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3.1 Compile-time errors . . . . . . . . . . . . . . . . . . . . . 4
1.3.2 Run-time errors . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3.3 Logic errors and semantics . . . . . . . . . . . . . . . . . 4
1.3.4 Experimental debugging . . . . . . . . . . . . . . . . . . . 5
1.4 Formal and natural languages . . . . . . . . . . . . . . . . . . . . 5
1.5 The first program . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.6 Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.7 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2 Variables and types 13
2.1 More output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.2 Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.3 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.4 Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.5 Outputting variables . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.6 Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.7 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.8 Order of operations . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.9 Operators for characters . . . . . . . . . . . . . . . . . . . . . . . 20
ii Contents
2.10 Composition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.11 Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.12 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3 Function 25
3.1 Floating-point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.2 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.3 Converting from double to int . . . . . . . . . . . . . . . . . . . 27
3.4 Math functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.5 Composition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
3.6 Adding new functions . . . . . . . . . . . . . . . . . . . . . . . . 29
3.7 Definitions and uses . . . . . . . . . . . . . . . . . . . . . . . . . 31
3.8 Programs with multiple functions . . . . . . . . . . . . . . . . . . 31
3.9 Parameters and arguments . . . . . . . . . . . . . . . . . . . . . 32
3.10 Parameters and variables are local . . . . . . . . . . . . . . . . . 33
3.11 Functions with multiple parameters . . . . . . . . . . . . . . . . . 34
3.12 Functions with results . . . . . . . . . . . . . . . . . . . . . . . . 34
3.13 Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
3.14 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
4 Conditionals and recursion 39
4.1 Conditional execution . . . . . . . . . . . . . . . . . . . . . . . . 39
4.2 The modulus operator . . . . . . . . . . . . . . . . . . . . . . . . 40
4.3 Alternative execution . . . . . . . . . . . . . . . . . . . . . . . . . 40
4.4 Chained conditionals . . . . . . . . . . . . . . . . . . . . . . . . . 41
4.5 Nested conditionals . . . . . . . . . . . . . . . . . . . . . . . . . . 41
4.6 The return statement . . . . . . . . . . . . . . . . . . . . . . . . 42
4.7 Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
4.8 Infinite recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
4.9 Stack diagrams for recursive functions . . . . . . . . . . . . . . . 45
4.10 Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
4.11 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Contents iii
5 Fruitful functions 49
5.1 Return values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
5.2 Program development . . . . . . . . . . . . . . . . . . . . . . . . 51
5.3 Composition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
5.4 Boolean values . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
5.5 Boolean variables . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
5.6 Logical operators . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
5.7 Bool functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
5.8 Returning from main() . . . . . . . . . . . . . . . . . . . . . . . 57
5.9 Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
5.10 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
6 Iteration 63
6.1 Multiple assignment . . . . . . . . . . . . . . . . . . . . . . . . . 63
6.2 Iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
6.3 The while statement . . . . . . . . . . . . . . . . . . . . . . . . . 64
6.4 Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
6.5 Two-dimensional tables . . . . . . . . . . . . . . . . . . . . . . . 68
6.6 Encapsulation and generalization . . . . . . . . . . . . . . . . . . 68
6.7 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
6.8 More encapsulation . . . . . . . . . . . . . . . . . . . . . . . . . . 70
6.9 Local variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
6.10 More generalization . . . . . . . . . . . . . . . . . . . . . . . . . 71
6.11 Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
6.12 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
7 Arrays 77
7.1 Increment and decrement operators . . . . . . . . . . . . . . . . . 78
7.2 Accessing elements . . . . . . . . . . . . . . . . . . . . . . . . . . 78
7.3 Copying arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
7.4 for loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
剩余128页未读,继续阅读
boyis
- 粉丝: 2
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- 2022年中国足球球迷营销价值报告.pdf
- 房地产培训 -营销总每天在干嘛.pptx
- 黄色简约实用介绍_汇报PPT模板.pptx
- 嵌入式系统原理及应用:第三章 ARM编程简介_3.pdf
- 多媒体应用系统.pptx
- 黄灰配色简约设计精美大气商务汇报PPT模板.pptx
- 用matlab绘制差分方程Z变换-反变换-zplane-residuez-tf2zp-zp2tf-tf2sos-sos2tf-幅相频谱等等.docx
- 网络营销策略-网络营销团队的建立.docx
- 电子商务示范企业申请报告.doc
- 淡雅灰低面风背景完整框架创业商业计划书PPT模板.pptx
- 计算模型与算法技术:10-Iterative Improvement.ppt
- 计算模型与算法技术:9-Greedy Technique.ppt
- 计算模型与算法技术:6-Transform-and-Conquer.ppt
- 云服务安全风险分析研究.pdf
- 软件工程笔记(完整版).doc
- 电子商务网项目实例规划书.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0