粘墙三角形pta c语言
时间: 2023-12-05 20:39:26 浏览: 159
以下是粘墙三角形的两种实现方法,分别对应引用和引用的代码:
1. 引用的实现方法:
```c++
#include <iostream>
using namespace std;
int main() {
int n;
while (cin >> n) {
for (int i = 1; i <= n; i++) {
char a = 97;
cout << a;
for (int j = n - i; j >= 1; j--) {
cout << " ";
}
char m = 97;
for (int l = n - i + 1; l <= n; l++) {
cout << m;
m++;
}
cout << endl;
}
}
return 0;
}
```
2. 引用的实现方法:
```c++
#include <iostream>
using namespace std;
int main() {
int n;
while (cin >> n) {
for (int i = 1; i <= n; i++) {
for (int j = n - i; j >= 1; j--) {
cout << " ";
}
char m = 97;
for (int l = n - i + 1; l <= n; l++) {
cout << m;
m++;
}
cout << endl;
}
}
return 0;
}
```
阅读全文