SHARE
TWEET

Untitled

a guest Dec 5th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. void init_matrix(int* C, int n, int m);
  3. void print_matrix(int* C, int n, int m);
  4. void zmeika_left_down_protch_lin(int* C, int n, int m);
  5.  
  6. int main()
  7. {
  8.     int m = 5;
  9.     int n = 5;
  10.     int* C = (int*)malloc(m * n * sizeof(int));
  11.     init_matrix(C, n, m);
  12.     print_matrix(C, n, m);
  13.     zmeika_left_down_protch_lin(C, n, m);
  14. }
  15. void init_matrix(int* C, int n, int m)
  16. {
  17.     for (int i = 0; i < n; i++)
  18.     {
  19.         for (int j = 0; j < m; j++)
  20.         {
  21.             C[m * i + j] = rand() % 100;
  22.         }
  23.     }
  24.     return;
  25. }
  26.  
  27. void print_matrix(int* C, int n, int m)
  28. {
  29.     printf("Matrix:\n");
  30.     for (int i = 0; i < n; i++)
  31.     {
  32.         for (int j = 0; j < m; j++)
  33.         {
  34.             printf("%3d", C[m * i + j]);
  35.  
  36.         }
  37.         printf("\n");
  38.     }
  39.     return;
  40. }
  41. void zmeika_left_down_protch_lin(int* C, int n, int m) {
  42.     int levo = 0, pravo = m - 1, verh = 0, niz = n - 1, gon = 0, pr = 0;
  43.     while (levo <= pravo && verh <= niz && pr < n * m) {
  44.         printf("\nprogon %d\n", gon);
  45.         for (int i = levo; i <= pravo; i++) {
  46.             if (pr == n * m)break;
  47.             printf("%d ", C[niz * m + i]);
  48.             pr++;
  49.         }
  50.         for (int i = niz - 1; i >= verh; i--) {
  51.             if (pr == n * m)break;
  52.             printf("%d ", C[i * m + pravo]);
  53.             pr++;
  54.         }
  55.         for (int i = pravo - 1; i >= levo; i--) {
  56.             if (pr == n * m)break;
  57.             printf("%d ", C[verh * m + i]);
  58.             pr++;
  59.         }
  60.         for (int i = verh + 1; i < niz; i++) {
  61.             if (pr == n * m)break;
  62.             printf("%d ", C[i * m + levo]);
  63.             pr++;
  64.         }
  65.         gon++;
  66.         levo++;
  67.         pravo--;
  68.         verh++;
  69.         niz--;
  70.     }
  71. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top