在C ++中打印不同的样式Bash
本文旨在使用C++编程语言打印半金字塔图案的bash。鉴于要打印的规定图案,正在精心设计以下算法以实现我们的目标:
算法
Step-1 Set the length of the Bash (Height) Step-2 Outer loop to handle the number of rows Step-3 Inner loop to handle columns Step-4 Print the pattern with the character (@) Step-5 Set the pointer to a new line after each row (outside the inner loop) Step-6 Repeat the loop till the Bash Height
示例
因此,通过遵循以下算法最终可以雕刻出以下C++源代码;
#include <iostream>
using namespace std;
void PrintBash(int n){
//外循环处理行数
for (int i=0; i<n; i++){
//内部循环以处理列数
for(int j=0; j<=i; j++ ){
//打印字符
cout << "@ ";
}
//每行后的结束行
cout << endl;
}
}
int main(){
int Len = 6;
PrintBash(Len);
return 0;
}输出结果
编译完上面的代码后,将按如下所示打印半金字塔。
@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
热门推荐
1 狗狗技能训练
5 如何训练狗狗笑
6 狗狗训练排便
9 狗狗响片训练
10 如何训练狗狗不捡食
11 狗狗尿训练
12 怎么训练狗狗找东西
13 狗狗训练站立
14 狗狗训练飞盘
15 鞍山狗狗训练
16 怎样训练泰迪狗狗谢谢
17 狗狗外出训练
18 怎么训练金毛狗狗大小便