c++编写函数输出图案等腰三角形,在主函数中输入n
#include <iostream>
#include <stdio.h>
using namespace std;
int f(int x)
{
x = x * 2;
for (int i = 1; i <= x; i += 2)
{
int y = (x - i) / 2;
for (int j = 1; j <= y; j++)
{
cout << ' ';
}
for (int j = 1; j <= i; j++)
{
cout << '*';
}
cout << endl;
}
}
int main()
{
int n;
while (cin >> n)
{
f(n);
}
return 0;
}
n为行数