使用双重循环输出n行的平行四边形(n为偶数)或倒三角形(n为奇数)。
时间: 2024-05-15 16:17:20 浏览: 13
以下是输出平行四边形的代码:
```C++
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
for (int i = 0; i < n / 2; i++) {
for (int j = 0; j < i; j++) {
cout << " ";
}
for (int j = 0; j < n / 2; j++) {
cout << "*";
}
cout << endl;
}
for (int i = n / 2; i < n; i++) {
for (int j = 0; j < n - i - 1; j++) {
cout << " ";
}
for (int j = 0; j < n / 2; j++) {
cout << "*";
}
cout << endl;
}
return 0;
}
```
以下是输出倒三角形的代码:
```C++
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i += 2) {
for (int j = 0; j < i / 2; j++) {
cout << " ";
}
for (int j = 0; j < n - i; j++) {
cout << "*";
}
cout << endl;
}
return 0;
}
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)