C语言英文课件4:选择结构

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Can show the logical execute process of algorithm better
basic shape of N-S flow cha源自文库t:
S1 block
S2 block is true
condition P
T
F
S1 block S2 block
while P is true S block
start
inputweight
true
false
weight≤50
pay=weight*0.35
pay=50*0.35+(weight-50)*0.5
2020/5/12
outputpay
end
2. N-S structural flow chart
Main feature:cancel flow line,adapt to structural programming,
• describing algorithm:natural language,flow chart,pslanguage
[example 4.1]algorithm description——natural language 1.input weight 2.comput value of pay based on weight 3.output value of pay
printf(weight= ); scanf(%f , &weight);
if (weight<=50) pay=weight*0.35 ;
else pay=50*0.35+(weight-50)*0.5;
printf( pay=%-7.2f , pay);
}
2020/5/12
basic steps of solving a problem: 0.analysis 1.setting variables 2.design the algorithm 3.writing the program list
Chapter 4 Selective Structure Programming
4.0 Foreword 4.1 Algorithm and Description 4.2 Conditional Operations and Condiyional Expression 4.3 Logical Operations and Logical Expression 4.4 if Statement 4.5 switch Statement 4.6 Examples of Selective Structure Programming
Start frame
End frame
I/O frame
operation frame
true
false
condition
distinguishing frame
2020/5/12
connect point
flow line
【example 4.1】algorithm description—traditional flow chart
analysis: not overweight 0.35*weight cost overweight 0.35*50+0.5*(weight-50)
2020/5/12
1、variables:weight,pay,are all real.
2、program list:
main ( )
{ float weight,pay;
A figure describs steps of an algorithm with kinds of prescriptive graphic symbols and lines with arrowhead.
symbols of flow chart:
start
I/O
operation
end
(1)sequence (4)until loop
2020/5/12
(2)selective
(3)while loop
S block until P
[example 4.1] algorithm description——N-S flow chart
first level algorithm
read in weight
comput pay based on weight’s value
Output pay
second level detailed algorithm
T
weight ≤50
F
pay=weight*0.35 pay=50*0.35+(weight-50)*0.5
2020/5/12
[ex. 4.1] Algorithm description—programming language
2020/5/12
4.0 Foreword
【 ex. 4.1】Compute the cost of baggage carried by train.Input the weight of the baggage, compute the cost. standard of cost: (1) lighter then 50 kg(include 50 kg), 0.35 yuan/kg (2) weighter then 50 kg,50 kg like (1),the other excess, 0.50yuan/kg
details of step 2 : if weight<=50 则 pay=weight*0.35
else 2020/5/12 pay=50*0.35+(weight-50)*0.5
4.1.1 Program Flow Chart 1.traditional flow chart(程序流程图)
4.1 Algorithm and Description
•Algroithm:Some restricted steps are taked inorder to solve a special problem.
•features :1. Limited(有穷性) 2. facticity(确定性)3. ≥0 input 4. >0 output 5. validity(有效性)
相关文档
最新文档