当前位置: 首页 > news >正文

打印图案、

描述

请编写一个程序,打印下面的图案:

输入

输出

打印上述图案

输入样例 1 

输出样例 1

*
* * *
* * * * *
* * * * * * *
* * * * *
* * *
*

代码一(如下):直接输出

#include <iostream>
using namespace std;
int main()
{cout << "*" << endl;cout << "* * *" << endl;cout << "* * * * *" << endl;cout << "* * * * * * *" << endl;cout << "* * * * *" << endl;cout << "* * *" << endl;cout << "*";return 0;
}

代码二(如下):采用字符数组的赋值与引用

#include <iostream>
using namespace std;
int main()
{char a[7][15] = { {'*'},{'*',' ','*',' ','*'},{'*',' ','*',' ','*',' ','*',' ','*'},{'*',' ','*',' ','*',' ','*',' ','*',' ','*',' ','*'},{'*',' ','*',' ','*',' ','*',' ','*'},{'*',' ','*',' ','*'},{'*'} };for (int i = 0; i < 7; i++){for (int j = 0; j < 15; j++)cout << a[i][j];cout << endl;}return 0;
}

代码三(如下):采用字符串数组

#include <iostream>
#include <string>
using namespace std;
int main()
{string a[7] = { "*","* * *","* * * * *","* * * * * * *","* * * * *","* * *","*" };for (int i = 0; i < 7; i++){cout << a[i];cout << endl;}return 0;
}

代码四(如下): 

#include <iostream>
using namespace std;
int main()
{char a[7][15];int i, j,t=1;for (i = 0; i < 7; i++){for (j = 0; j < t; j++){if (j == 0 || j % 2 == 0){a[i][j] = '*';cout << a[i][j];}else{a[i][j] = ' ';cout << a[i][j];}}cout<<endl;if (i <= 2)t += 4;else t -= 4;}return 0;
}
http://www.lryc.cn/news/111226.html

相关文章:

  • # Windows 环境下载 Android 12源码
  • 【运维面试】Docker技术面试题总结
  • CNN成长路:从AlexNet到EfficientNet(01)
  • 使用IDEA操作Mysql数据库
  • ChatGPT下架官方检测工具,承认无法鉴别AI内容
  • Java通过实例调用getClass()方法、类名.class操作、通过运行时类获取其它信息
  • UE5+Paperzd问题
  • K8S系列文章之 自动化运维利器 Ansible
  • Julia 字典和集合
  • devops-发布vue前端项目
  • 使用正则表达式设置强密码
  • epoll、poll、select的原理和区别
  • 【学习笔记】Java安全之反序列化
  • 算法练习--leetcode 数组
  • 本地 shell无法连接centos 7 ?
  • C 语言的基本算术运算符 = + - * /
  • SQL注入实操三(SQLilabs Less41-50)
  • HOT77-买卖股票的最佳时机
  • CSS调色网有哪些
  • Day10-NodeJS和NPM配置
  • 线性代数 | 机器学习数学基础
  • Nios初体验之——Hello world!
  • [Linux]理解文件系统!动静态库详细制作使用!(缓冲区、inode、软硬链接、动静态库)
  • 【Linux操作系统】Vim:提升你的编辑效率
  • Mybatis-plus 的自动填充策略
  • 大数据课程G2——Hbase的基本架构
  • 微信小程序wx.getlocation接口权限申请总结
  • 简单游戏截图_可控截取内容1
  • Vue3_02 创建Vue3.0工程
  • Arduino ESP 8266 ESPAsyncWebServer AsyncCallbackJsonWebHandler