Josif_tepe

Untitled

May 2nd, 2026
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int main(){
  5.     int n, m;
  6.     cin >> n >> m;
  7.    
  8.     if(n != m) {
  9.         cout << "Ne vnesovte kvadratna matrica!" << endl;
  10.         return 0;
  11.     }
  12.    
  13.     int mat[n][n];
  14.    
  15.     for(int i = 0; i < n; i++) {
  16.         for(int j = 0; j < n; j++) {
  17.             cin >> mat[i][j];
  18.         }
  19.     }
  20.    
  21.     int W = 0;
  22.     for(int i = 0; i < n; i++) {
  23.         for(int j = 0; j < i; j++) {
  24.             W += mat[i][j];
  25.         }
  26.     }
  27.    
  28.     int Q = 1;
  29.     for(int i = 0; i < n; i++) {
  30.         Q *= mat[i][n - 1 - i];
  31.     }
  32.    
  33.     int B[n][n];
  34.     for(int i = 0; i < n; i++) {
  35.         for(int j = 0; j < n; j++) {
  36.             if(i == j) {
  37.                 B[i][j] = W;
  38.             }
  39.             else {
  40.                 B[i][j] = Q - mat[i][j];
  41.             }
  42.         }
  43.     }
  44.    
  45.     for(int i = 0; i < n; i++) {
  46.         for(int j = 0; j < n; j++) {
  47.             cout << B[i][j] << " ";
  48.         }
  49.         cout << endl;
  50.     }
  51.    
  52.    
  53.     return 0;
  54. }
  55.  
  56.  
  57.  
Advertisement
Add Comment
Please, Sign In to add comment