ValerianBenchea

Problema

Oct 11th, 2021
1,137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. int a[101][101], n;
  5. void ordonare_matrice(int n)
  6. {
  7.     int i, j;
  8.     for(i=0; i<n; i++)
  9.         for(j=0; j<n; j++)
  10.         {
  11.             if(i==j || i+j==n-1)
  12.                 a[i][j]=0;
  13.             else if(i+j<n)
  14.                 a[i][j]=i+j;
  15.             else
  16.                 a[i][j]=abs((n-1)-(i+j));
  17.         }
  18. }
  19. void afisare_matrice(int n)
  20. {
  21.     int i, j;
  22.     for(i=0; i<n; i++)
  23.     {
  24.         for(j=0; j<n; j++)
  25.             cout<<a[i][j]<<' ';
  26.         cout<<'\n';
  27.     }
  28.  
  29. }
  30. int main()
  31. {
  32.     cin>>n;
  33.     ordonare_matrice(n);
  34.     afisare_matrice(n);
  35.     return 0;
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment