-5
这个字母图案是否有任何其他的方式做这个节目用更少的loops.Its没有多少有效的计划在C++中
#include <iostream>
using namespace std;
int main() {
int i,j,n,s;
cout<<"Enter the value of n";
cin>>n;
for(i=1;i<=n;i++){
for(s=1;s<=n-i;s++){
cout<<" ";
}
char ch=97;
int k=1;
for(j=1;j<=(i*2-1);j++) {
if (k%2!= 0){
cout <<ch;
ch++;
} else {
cout<<" ";
}
k++;
}
cout<<endl;
}
}
输出的数量:
Enter the value of n6
a
a b
a b c
a b c d
a b c d e
a b c d e f
比少?它看起来应该可以使用嵌套在另一个循环中的一个循环来实现。 – user3553031
更少的循环数?为什么不只是以这种格式打印它们:P – P0W
你的问题还不清楚,但我想这可以用一个循环来完成,每一行作为一个字符串。 –