7章5节for循环嵌套

来源:互联网 发布:忧郁眼神知乎 编辑:程序博客网 时间:2024/06/08 04:33

#include<iostream>
int main()
{
 using namespace std;

 int rows,columns;
 char theChar;

 cout <<"how many rows?";
 cin >> rows;
 cout <<"how many columns?";
 cin >> columns;
    cout << "what character?";
 cin >> theChar;

 for(int i=0; i < rows;i++) //初始化I=0 小于max的时候 则 i++ 进入循环的第一句
 {
  for(int j=0; j < columns; j++) //初始化j=0 ... 当j!<clomns 则返回外层循环 验证i的值与rows的关系....
   cout << theChar;
  cout<<endl;
 }
 return 0;
}

原创粉丝点击