做药材生意的网站口碑营销成功案例简短
描述
请编写一个程序,打印下面的图案:
输入
无
输出
打印上述图案
输入样例 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;
}