Răspuns :
Răspuns:
#include <iostream>
using namespace std;
int marimeMatrice;
int matrice[100][100];
void citireValori(){
cout << "Te rog sa introduci marimea matricei :";
cin >> marimeMatrice ;
cout << "Te rog sa introduci elementele :";
for (int i = 1; i <= marimeMatrice; i++){
for (int j = 1; j <= marimeMatrice; j++){
cin >> matrice[i][j];
}
}
}
void afisareValori(){
cout << "Afisarea tuturor valorilor";
for (int i = 1; i <= marimeMatrice; i++){
cout << "" << endl;
for(int j = 1; j <= marimeMatrice; j++){
cout << matrice[i][j] << " ";
}
}
cout << endl;
}
void afisareDiagonala(){
cout << "Afisarea valorilor de pe diagonala principala";
for (int i = 1; i <= marimeMatrice; i++){
cout << "" << endl;
for(int j = 1; j <= marimeMatrice; j++){
if (i == j){cout << matrice[i][j] << " ";}
}
}
cout << "Afisarea valorilor de pe diagonala secundara" << endl;
for (int i = 1; i <= marimeMatrice; i++){
cout << "" << endl;
for(int j = 1; j <= marimeMatrice; j++){
if (i + j == marimeMatrice){cout << matrice[i][j] << " ";}
}
}
}
void afisareNumereNenule(){
cout << "Afisarea numarului de valori nenule de pe fiecare linie";
int numarator = 0;
for (int i = 1; i <= marimeMatrice; i++){
for(int j = 1; j <= marimeMatrice; j++){
if (matrice[i][j] != 0){numarator++;}
if(j == marimeMatrice){
cout << "Linia " << i << " : " << numarator << endl;
numarator = 0;
}
}
}
}
void afisareNumerePozitive(){
cout << "Afisarea numarului de elemente pozitive de pe fiecare coloana:";
int numarator = 0;
for (int i = 1; i <= marimeMatrice; i++){
for(int j = 1; j <= marimeMatrice; j++){
if (matrice[j][i] > 0){numarator++;}
if(j == marimeMatrice){
cout << "Coloana " << i << " : " << numarator << endl;
numarator = 0;
}
}
}
}
void afisareNumereImpare(){
cout << "Afisarea numarului de elemente impare de pe fiecare diagonala:"<<endl;
int numaratorPrincipala = 0;
int numaratorSecundara = 0;
for (int i = 1; i <= marimeMatrice; i++){
for(int j = 1; j <= marimeMatrice; j++){
if(i == j && matrice[i][j] % 2 == 1){numaratorPrincipala++;}
if(i + j == marimeMatrice && matrice[i][j] % 2 == 1){numaratorSecundara++;}
}
}
cout << "Numarul de elemente impare de pe diagonala principala : "<< numaratorPrincipala<< endl;
cout << "Numarul de elemente impare de pe diagonala secundara : "<< numaratorSecundara<< endl;
}
int main()
{
citireValori();
afisareValori();
afisareDiagonala();
afisareNumereNenule();
afisareNumerePozitive();
afisareNumereImpare();
return 0;
}
Explicație: