Răspuns:
#include <iostream>
using namespace std;
int main()
{
int n, i, j, m[10][10];
cin >> n;
for (i=1; i<=n; i++)
{
for (j=1; j<=n; j++)
if (i==1 || i==n || j==1 || j==n)
m[i][j]=1;
else m[i][j]=2;
}
cout << "Matricea creata:" << endl;
for (i=1; i<=n; i++)
{
for (j=1; j<=n; j++)
cout << m[i][j] << " ";
cout << endl;
}
return 0;
}
Explicație: