Advertisement
Josif_tepe

Untitled

Dec 18th, 2022
848
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int n;
  7.     cin >> n;
  8.    
  9.     int mat[n][n];
  10.    
  11.     for(int i = 0; i < n; i++) {
  12.         for(int j = 0; j < n; j++) {
  13.             cin >> mat[i][j];
  14.         }
  15.     }
  16.     // glavna dijagonala
  17.     int zbir = 0;
  18.     for(int i = 0; i < n; i++) {
  19.         zbir += mat[i][i];
  20.     }
  21.    
  22.     // sporedna dijagonala
  23.     int zbir_sporedna = 0;
  24.     for(int i = 0; i < n; i++) {
  25.         zbir_sporedna += mat[i][n - 1 - i];
  26.     }
  27.    
  28.     cout << zbir << endl;
  29.     cout << zbir_sporedna << endl;
  30.     return 0;
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement