使用for循环打印矩阵
加强for循环思维
1.
#include<iostream>
using namespace std;
int main(){
for(int j=1;j<7;++j){
cout<<j<<" ";
for(int i=j-1;i<j+6;++i)
cout<<i%7<<" ";
cout<<"\n";
}
}
截图:
2.
#include<iostream>
using namespace std;
int main(){
for(int j=1;j<7;++j){
for(int i=1;i<8;++i)
{
cout<<"("<<j<<","<<i<<")";
cout<<" ";
}
cout<<"\n";
}
}
截图:
总结:
for循环可以做任何循环,当要输出一些循环时,主要思考其数学模型,然后就很简单了。