用c++输出一个4*7的倒三角形
时间: 2024-02-13 08:05:04 浏览: 35
下面是用 C++ 输出一个 4*7 的倒三角形的代码:
```cpp
#include <iostream>
using namespace std;
int main()
{
for(int i=1;i<=4;i++)
{
for(int j=1;j<=i-1;j++)
{
cout<<" ";
}
for(int j=1;j<=2*(4-i)+1;j++)
{
cout<<"*";
}
cout<<endl;
}
return 0;
}
```
输出结果如下:
```
*******
*****
***
*
```
相关问题
用c++做一个倒过来的直角三角形
以下是C++代码实现:
```c++
#include <iostream>
using namespace std;
int main() {
int n;
cout << "请输入直角三角形的行数: ";
cin >> n;
// 打印倒过来的直角三角形
for (int i = n; i >= 1; i--) {
for (int j = 1; j <= i; j++) {
cout << "*";
}
cout << endl;
}
return 0;
}
```
输出结果:
```
请输入直角三角形的行数: 5
*****
****
***
**
*
```
c++ 输入一个整数n,输出一个倒的空心三角形 输入描述 输入一个整数n,n大于等于5小于等于100 输出描述 输出一个倒的空心三角形,图形用*表示 用例输入 1 5 用例输出 1 ***** * * * * ** *
以下是实现倒的空心三角形的C++代码:
```cpp
#include <iostream>
using namespace std;
void printHollowTriangle(int n) {
for (int i = n; i >= 1; i--) {
for (int j = 1; j <= n - i; j++) {
cout << " ";
}
for (int j = 1; j <= i; j++) {
if (i == n || j == 1 || j == i) {
cout << "*";
} else {
cout << " ";
}
}
cout << endl;
}
}
int main() {
int n;
cin >> n;
printHollowTriangle(n);
return 0;
}
```
相关推荐
![text/x-c](https://img-home.csdnimg.cn/images/20210720083646.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)