1、输出N个*;

1 #include <IOSTREAM.H> 2 void main() 3 { 4 int m; 5 cout<<"请输入*的个数:"<<endl; 6 cin>>m; 7 while(m) 8 { 9 cout<<"*"; 10 m--; 11 } 12 cout<<endl; 13 }
2、输出由N个*组成的矩形:
1 #include <IOSTREAM> 2 using namespace std; 3 void main() 4 { 5 int m,n; 6 cout<<"请输入*的行数:"<<endl; 7 cin>>m; 8 cout<<"请输入*的列数:"<<endl; 9 cin>>n; 10 for (int i=0;i<m;i++) 11 { 12 for (int j=0;j<n;j++) 13 { 14 cout<<"*"; 15 } 16 cout<<endl; 17 } 18 }
3、输出由*号组成的左下三角矩阵
1 #include <IOSTREAM> 2 using namespace std; 3 void main() 4 { 5 int m; 6 cout<<"请输入*的行数:"<<endl; 7 cin>>m; 8 for (int i=0;i<m;i++) //控制输出的行数 9 { 10 for (int j=0;j<=i;j++)//控制前一个循环每一行中的*的个数 11 { 12 cout<<"*"; 13 } 14 cout<<endl; 15 } 16 }
4、输出由*号组成的左上三角矩阵
1 #include <IOSTREAM> 2 using namespace std; 3 void main() 4 { 5 int m; 6 cout<<"请输入*的行数:"<<endl; 7 cin>>m; 8 for (int i=0;i<m;i++) //控制输出的行数 9 { 10 for (int j=m-i;j>0;j--)//控制前一个循环每一行中的*的个数 11 { 12 cout<<"*"; 13 } 14 cout<<endl; 15 } 16 }
5、输出由*号组成的右下三角矩阵
1 #include <IOSTREAM> 2 using namespace std; 3 void main() 4 { 5 int m; 6 cout<<"请输入*的行数:"<<endl; 7 cin>>m; 8 for (int i=0;i<m;i++) //控制输出的行数 9 { 10 for (int j=m-i;j>0;j--)//控制空格的个数 11 { 12 cout<<" "; 13 } 14 for (int k=0;k<=i;k++)//控制每一行中的*的个数,与前一个for同时进行 15 { 16 cout<<"*"; 17 } 18 cout<<endl; 19 } 20 }
6、输出由*号组成的右上三角矩阵
1 #include <IOSTREAM> 2 using namespace std; 3 void main() 4 { 5 int m; 6 cout<<"请输入*的行数:"<<endl; 7 cin>>m; 8 for (int i=0;i<m;i++) //控制输出的行数 9 { 10 for (int j=0;j<i;j++)//控制空格的个数 11 { 12 cout<<" "; 13 } 14 for (int k=m-i;k>0;k--)//控制每一行中的*的个数,与前一个for同时进行 15 { 16 cout<<"*"; 17 } 18 cout<<endl; 19 } 20 }