#include<iostream>
using namespace std;
void main()
{
int num = 0;
char character;
cout << "How many lines?" << endl;
cin >> num;
cout << "What character?" << endl;
cin >> character;
for (int i = 1; i <= num; i++)
{
for (int j = 1; j <= num - i; j++)
cout << " ";
for (int j = 1; j <= (2 * i - 1); j++)
cout << character;
cout << endl;
}
system("pause");
}
在for语句(int j;...)定义的变量具有块作用域,只在for中有效,此后可以用回那个标识符;
char型赋值' '.