用循环语句编程打印如下图案:
%
%%%
%%%%%
%%%%%%%
%%%%%%%%%
%%%%%%%%%%%
%%%%%%%%%%%%%
%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%
%%%%%%%%%%%%%
%%%%%%%%%%%
%%%%%%%%%
%%%%%%%
%%%%%
%%%
%
#include <iostream> #include <cmath> #include <iomanip> using namespace std; int main() { for (int i = 10; i > 1; i--) { for (int j = 0; j <= i; j++) { cout << ' '; } for (int k = 0; k < 20 - (2 * i) - 1; k++) { cout << '%'; } cout << endl; } for (int i = 1; i < 10; i++) { for (int j = 0; j <= i; j++) { cout << ' '; } for (int k = 0; k < 20 - (2 * i) - 1; k++) { cout << '%'; } cout << endl; } }
#include <iostream> using namespace std; int main() { for(int i=1;i<11;i++) { for(int j=10-i;j>0;j--) { cout<<" "; } for(int k=1;k<=2*i-1;k++) { cout<<"%"; } for(int m=10-i;m>0;m--) { cout<<" "; } cout<<"\n"; } for(int n=9;n>0;n--) { for(int x=1;x<=10-n;x++) { cout<<" "; } for(int y=1;y<=2*n-1;y++) { cout<<"%"; } for(int z=1;z<=10-n;z++) { cout<<" "; } cout<<"\n"; } return 0; }