Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int afisareConturMatrice(int matrice[][5], int n)
- {
- int suma = 0;
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- if (i == 0) {
- if (matrice[i][j] % 2 != 0)
- suma += matrice[i][j];
- }
- else if (i == n - 1) {
- if (matrice[i][j] % 2 != 0)
- suma += matrice[i][j];
- }
- else if (j == 0) {
- if (matrice[i][j] % 2 != 0)
- suma += matrice[i][j];
- }
- else if (j == n - 1) {
- if (matrice[i][j] % 2 != 0)
- suma += matrice[i][j];
- }
- }
- }
- return suma;
- }
- void afisareMatrice(int matrice[][5], int n)
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- cout << matrice[i][j] << " ";
- }
- cout << endl;
- }
- }
- int main()
- {
- int matrice[5][5] = {
- { 1, 1, 1, 1, 1 },
- { 1, 7, 8, 9, 1 },
- { 1, 12, 13, 14, 1 },
- { 1, 17, 18, 19, 1 },
- { 1, 1, 1, 1, 1 }
- };
- int n = 5;
- afisareMatrice(matrice, n);
- cout << endl;
- cout << "Suma: " << afisareConturMatrice(matrice, n) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment