自己写的两个for循环
#include<iostream>
using namespace std;
int main()
{
int n,m,k=1;
cin>>n>>m;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(j==m-1)
{
k++;
cout<<"PUM";
break;
}
cout<<k<<' ';
k++;
}
cout<<endl;
}
}
大佬的简单写法
#include<iostream>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
for(int j=1;j<=n*m;j++)
{
if(j%m==0)
cout<<"PUM"<<endl;
else
cout<<j<<" ";
}
return 0;
}
感觉自己写的好麻烦啊,还是要向大佬学习😔
多练