Background
Description
打印对称的直角三角形。
根据输入的n(正整数,n<=1<=20),如:输入n=5:
![](https://img-blog.csdnimg.cn/direct/eaf7ec6587bd4069a83916c180cb7398.png)
输入:
第一行输入n
输出:
输出相应的图形
Samples
输入数据 1
5
输出数据 1
*****
****
***
**
*
**
***
****
*****
输入数据 2
10
输出数据 2
**********
*********
********
*******
******
*****
****
***
**
*
**
***
****
*****
******
*******
********
*********
**********
代码如下:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
for (int i=1; i<=n-1; i++)
{
for (int j=1; j<=n; j++)
{
if (j<i)
cout<<" ";
else
cout<<"*";
}
cout<<endl;
}
for (int i=1; i<=n; i++)
{
for (int j=1; j<n; j++)
cout<<" ";
for (int j=1; j<=i; j++)
cout<<"*";
cout<<endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
for (int i=1; i<=n-1; i++)
{
for (int j=1; j<=n; j++)
{
if (j<i)
cout<<" ";
else
cout<<"*";
}
cout<<endl;
}
for (int i=1; i<=n; i++)
{
for (int j=1; j<n; j++)
cout<<" ";
for (int j=1; j<=i; j++)
cout<<"*";
cout<<endl;
}
return 0;
}