Advertisement
LegoDrifter

broken matrica

Jan 30th, 2020
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.21 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.     int n,j,m[50][50],x,y,i;
  7.     scanf("%d",&n);
  8.     for(i=0;i<n;i++)
  9.     {
  10.         for(j=0;j<n;j++)
  11.         {
  12.             scanf("%d",&m[i][j]);
  13.         }
  14.     }
  15.     for(i=0;i<n;i++)
  16.     {
  17.         for(j=0;j<n;j++)
  18.         {
  19.             if(j>i)
  20.             {
  21.                 x+=m[i][j];
  22.             }
  23.             else if(i>j)
  24.             {
  25.                 y+=m[i][j];
  26.             }
  27.            
  28.  
  29.         }
  30.         for(i=0;i<n;i++)
  31.         {
  32.             for(j=0;j<n;j++)
  33.             {
  34.                 if(i==j)
  35.                 {
  36.                     m[i][j]=x;
  37.                 }
  38.                 else if((i+j)==(n-1))
  39.                 {
  40.                     m[i][j]=y;
  41.                 }
  42.                 else if(i&&j==(n-1)/2)
  43.                 {
  44.                 m[i][j]=x+y;
  45.                 }
  46.                 else
  47.                 {
  48.                 m[i][j]=0;
  49.                 }
  50.                 }
  51.            
  52.         }
  53.         for(i=0;i<n;i++)
  54.         {
  55.             for(j=0;j<n;j++)
  56.             {
  57.             printf("%.1f ",(float)m[i][j]);
  58.            
  59.             }
  60.        
  61.         printf("\n");
  62.         }
  63.     }
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement