Advertisement
jordanov

zad4 #matrici

Dec 10th, 2015
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. // Matricata treba da ja smenite, taka shto novata vrednost na sekoj element ke bide zbirot na negovite sosedi.
  5.  
  6.  
  7. int main()
  8. {
  9.     int n,m,i,j,a[100][100];
  10.  
  11.     scanf("%d%d", &n, &m);
  12.  
  13.     for(i=0;i<n+2;i++)
  14.     {
  15.         for(j=0;j<m+2;j++)
  16.         {
  17.             a[i][j] = 0;
  18.         }
  19.     }
  20.     for(i=1;i<n+1;i++)
  21.     {
  22.         for(j=1;j<m+1;j++)
  23.         {
  24.             scanf("%d", &a[i][j]);
  25.         }
  26.     }
  27.  
  28. int    b[100][100];
  29.  
  30.     for(i=1;i<n+1;i++)
  31.     {
  32.         for(j=1;j<m+1;j++)
  33.         {
  34.             b[i][j] = a[i-1][j] + a[i+1][j] + a[i][j-1] + a[i][j+1];
  35.         }
  36.     }
  37.     for(i=1;i<n+1;i++)
  38.     {
  39.         for(j=1;j<m+1;j++)
  40.         {
  41.             printf("%d", b[i][j]);
  42.         }
  43.     }
  44.  
  45.  
  46.  
  47.  
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement