using namespace std;
int main()
{int x[10][10], n, m, i, j;
cout<<"Dati numarul de linii: ";cin>>n;
cout<<"Dati numarul de coloane: ";cin>>m;
cout<<"Introduceti elementele matricei: "<<endl;
for(i=0;i<n;i++)
for(j=0;j<m;j++)
{
cout<<"x["<<i<<"]["<<j<<"]=";cin>>x[i][j];
}
cout<<"Afisam matricea: "<<endl;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{cout<<x[i][j]<<" ";
cout<<endl;}
}
cout<<"Diagonala principala: "<<endl;
for(i=1; i<=n; i++)
{for(j=1; j<=n; j++)
if(i==j) cout<<x[i][j]<<" ";
cout<<"\n diagonala secundara: "<<endl;}
for(i=1; i<=n; i++)
{
for(j=1; j<=n; j++)
{
if(i+j==n+1) cout<<x[i][j]<<" ";
cout<<endl;
else cout<<"0";}}
cout<<"n elementele de deasupra diagonalei principale: "<<endl;
for(i=1; i<=n; i++)
{
for(j=1; j<=n; j++)
if(i<j) cout<<x[i][j]<<" ";
cout<<endl;
}
cout<<"n elementele de sub diagonala principala: "<<endl;
for(i=1; i<=n; i++)
{
for(j=1;j<=n; j++)
if(i>j) cout<<x[i][j]<<" ";
cout<<endl;
}
cout<<endl<<"elementele de deasupra diagonalei secundare: "<<endl;
for(i=1; i<=n-1; i++)
for(j=1; j<=n-2; j++)
cout<<x[i][j]<<" ";
cout<<endl<<"elementele de sub diagonala secundara: "<<endl;
for(i=2; i<=n; i++)
for(j=n; j<=n-i; j++)
cout<<x[i][j]<<" ";
return 0;}
Niciun comentariu:
Trimiteți un comentariu