第三周上机实践项目——项目3-输出星号图
2016-03-12 19:25
429 查看
/* *Copyright (c)2016,烟台大学计算机与控制工程学院 *All rights reserved. *文件名称:main.cpp *作 者:郭永恒 *完成日期:2016年3月12日 *版 本 号:v1.0 * *问题描述:输出星号图 *输入描述:无 *输出描述:看运行结果 */ #include <iostream> using namespace std; int main() { int i, j; for (i=0; i<5; i++) { for (j=0; j<4-i; j++) cout <<" "; for (j=0; j<2*i+1; j++) cout << "*"; cout << endl; } for (i=3; i>=0; i--) { for (j=0; j<4-i; j++) cout << " "; for (j=0; j<2*i+1; j++) cout << "*"; cout <<endl; } return 0; }
运行结果:
#include <iostream>
using namespace std;
int main()
{
int i, j;
for (i=0; i<5; i++)
{
for (j=0; j<=4-i; j++)
cout << " ";
if (i == 0)
cout << "*";
else
{
cout << "*";
for (j=0; j<2*i-1; j++)
cout << " ";
cout << "*";
}
cout << endl;
}
for(i = 0; i < 11; ++i)
cout << "*";
return 0;
}运行结果:
知识点总结:
用嵌套循环时要小心
相关文章推荐
- 读书笔记:Mastering the game of Go with deep neural networks and tree search
- spring @RequestBody The request sent by the client was syntactically incorrect.
- 密码强度等级
- 证明正方形和圆有交点
- 两个链表的第一个公共结点
- Java线程:概念与原理
- C++字符串学习(三)
- Image I/O
- 个人所得税计算器
- POJ3687 Labeling Balls(拓扑排序\贪心+Floyd)
- 永久删除 tadb.exe
- Nginx配置多个项目使用同一端口号的办法
- 抓包工具:Charles-断点
- bootstrap导航
- 单选对话框
- 抽象了若干个知识点
- Ubuntu开机时出现"没有正确安装GNOME电源管理器的默认配置
- CodeForces - 630C Lucky Numbers
- [HNOI2008][BZOJ1010] 玩具装箱toy - 斜率优化
- Mina框架研究