简单的了解了一些循环算法后,尝试用循环算法,输出形状图形
例1矩形与平行四边形的比较(可以看做矩形的每一行在输出前都输出了矩形长度数量-1的空格数量并且依次递减)
例2三角形(三角形可看做半个矩形,考虑为每一行输出空格后每一行多出书一个*号,寻找*号与行数和列数的关系,构造对应的数学公式规定其范围和数量)
例3 星号菱形的两种示例(菱形可以看做两个三角形相互拼接,
也可以以中心线为轴,做正负值得运算(以最长的长度为值,做正负运算,一个数为一个数字长度7长度是(-3到整3))
总结
更具上面两个对比的例子,我们可得出一些规则的形状(对称的形状)都是由一定的基本形状转换出来的,只要找出其中的规律,代码就会很简 单
规律寻找:
1.找出输出的*号数量与形状输出行数和列数的关系;
2.输出空格数学规律的寻找,若是奇数(X*2-1);
3.例出图形查找每一行*号数量,每一行空格数量,寻找其中的数学规律;