Răspuns :
#include <stdio.h>
#include <stdlib.h>
int n,i,j,k,p;
int a[100][100];
main(){
printf("Dati dimensiunea matricii n = ");
scanf("%d",&n);
for(i=0; i<n; i++){
for(j=n-i-1; j<n-i; j++){
a[i][j]=2;
}
}
for(i=0; i<n; i++){
for(j=i; j<i+1; j++){
a[i][j]=1;
}
}
for(i=0; i<n; i++){
printf("\n");
for(j=0; j<n; j++){
printf("%d ",a[i][j]);
}
}
}
#include <iostream>
using namespace std;
short n, i, j, v[100][100];
int main()
{
cout << "n= "; cin >> n;
for (i=0; i<n; ++i) { v[i][i]=1; v[i][n-1-i]=2; }
cout << " matricea generata: \n";
for (i=0; i<n; ++i)
{
for (j=0; j<n; ++j)
cout << v[i][j] << " ";
cout << "\n";
}
}