第3章结构化程序设计 —程序的灵魂
第3章 结构化程序设计 ——程序的灵魂
5.3算法的表示 自然语言描述法 ◆流程图描述法 ·伪代码描述法 ◆N-S流程图描述法
5.3 算法的表示 自然语言描述法 流程图描述法 伪代码描述法 N-S流程图描述法
2传统流程图描述法 算法常用“流程图”描述,更直观,容易阅读 和理解。 ·流程图中基本的图形符号 菱形框 (条件判断框) 无角矩形框 矩形框 (开始/结束框) 平行四边形框 (操作框) (输入/输出框) 流程线
2 传统流程图描述法 算法常用“流程图”描述,更直观,容易阅读 和理解。 流程图中基本的图形符号 无角矩形框 (开始/结束框) 矩形框 (操作框) 菱形框 (条件判断框) 平行四边形框 (输入/输出框) 流程线
功能:已知苹果价格和公斤数,求苹果总 价格的流程图 开始 void main() { 输入苹果每公斤价格price scanf(“%f”,&price); 输入苹果公斤数quantity scanf(“%d”,&quantity); totalPrice-price*quantity totalPrice=price quantity; 输出totalPrice printf(“%fr”,totalPrice); 结束
totalPriceprice*quantity 开始 结束 输出totalPrice 输入苹果每公斤价格 price 功能:已知苹果价格和公斤数,求苹果总 价格的流程图 输入苹果公斤数 quantity void main() { scanf(“%f”,&price); scanf(“%d”,&quantity); totalPrice=price * quantity; printf(“%f”,totalPrice); }
void main() 变量定义 float price,totalPrice; int quantity; 数据输入 scanf(%f”,&price); scanf("%od",&quantity); 数据处理 totalPrice=price quantity;" printf("%f,totalPrice) 数据输出
void main() { float price,totalPrice; int quantity; scanf(“%f”,&price); scanf(“%d”,&quantity); totalPrice=price * quantity; printf(“%f”,totalPrice); } 变量定义 数据输入 数据处理 数据输出