Răspuns:
#include <iostream>
using namespace std;
int n, m, a, b, c, d, cadru, i, j, t[100][100];
int main()
{
cout << "nr. de linii n= "; cin >> n;
cout << "nr. de coloane m= "; cin >> m;
cout << "Matricea cadru: " << endl;
a=1; b=1; c=n; d=m; cadru=0;
while (a<=c && b<=d)
{
++cadru;
for (i=a; i<=c; ++i)
{
t[i][b]=cadru; t[i][d]=cadru;
}
for (j=b+1; j<d; ++j)
{
t[a][j]=cadru; t[c][j]=cadru;
}
++a; ++b; --c; --d;
}
cout << "Matricea cadru: " << endl;
for (i=1; i<=n; ++i)
{
for (j=1; j<=m; ++j)
cout << t[i][j] << " ";
cout << "\n";
}
return 0;
}
Explicație: