伪代码教程
起一篇伪代码基础教程
伪代码(Pseudo code)是一种介于计算机语言
和自然语言
间的文字和符号,是表达算法的简单而有效的方法。伪代码不需要关注底层是如何实现的,本身就是算法框架的逻辑模型。
一、赋值语句
赋值号 A ← B A\leftarrow B A←B,表示将 B B B的内容传递给 A A A,相当于: A = B A=B A=B
二、输入输出
输入
I n p u t : i n p u t p a r a m e t e r s A , B , C Input:\ input\ parameters\ A,B,C Input: input parameters A,B,C
输出
O u t p u t : o u t p u t r e s u l t Output:\ output \ result Output: output result
三、条件语句
I f A t h e n B E l s e C E n d i f If\ A \ then \ B \\ Else \ C \\ End\ if If A then BElse CEnd if
四、循环语句
4.1 for循环
f o r i = 1 → i = N d o e n d f o r for\ i=1\rightarrow i=N\ do\\ end \ for for i=1→i=N doend for
4.2 while循环
W h i l e A Y o u r s e n t e n c e s E n d w h i l e While \ A \\ Your\ sentences \\ End \ while While AYour sentencesEnd while
一个简单的栗子
🔶