Advertisement
Guest User

Untitled

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