逛奔的蜗牛

我不聪明,但我会很努力

   ::  :: 新随笔 ::  ::  :: 管理 ::

   *

  ***

 *****

*******

 *****

  ***

   *

// 这几天奇怪了,要输出菱形程序的人好多。

#include <iostream>

#include <cmath>


int main() {

const int row = 5; // 5行,对于行对称的,使用绝对值来做比较好

const int max = row / 2 + 1;


for (int i = -max + 1; i < max; ++i) {

for (int j = 0; j < abs(i); ++j, std::cout << " ");

for (int j = 0; j < (max - abs(i)) * 2 - 1; ++j, std::cout << "*");

std::cout << std::endl;

}


return 0;

}


posted on 2010-10-05 01:11 逛奔的蜗牛 阅读(1239) 评论(0)  编辑 收藏 引用 所属分类: JavaC/C++其他编程

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理