在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;
}输出结果
编译完上面的代码后,将按如下所示打印半金字塔。
@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短