实例要求:
金字塔代码:
#include <iostream> using namespace std; int main() { for(int i=1; i<=10; i++){ for(int j=1; j<=10-i; j++) cout <<" "; for(int k=1; k<=2*i-1; k++) cout <<"#"; cout <<endl; } }
运行结果:
倒金字塔代码:
#include <iostream> using namespace std; int main() { for(int i=1; i<=8; i++){ for(int j=1; j<=i-1; j++) cout <<" "; for(int k=1; k<=18-i; k++) cout <<" #"; cout <<endl; } }
运行结果: