打印图案、

描述

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

输入

输出

打印上述图案

输入样例 1 

输出样例 1

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

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

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

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

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

代码四(如下): 

#include 
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<


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部