Advertisement
AndreyKlipikov

Prog. Zachet. N2

Jan 7th, 2014
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. int main() {
  6.     const int n = 4;
  7.     int a[2 * n][2 * n], stol = 0;
  8.     srand(time(NULL));
  9.  
  10.     for(int i = 0; i < n; i++) {
  11.         for(int j = 0; j < n; j++) {
  12.             a[i][j] = rand() % 10 - 4;
  13.             printf("%d\t", a[i][j]);
  14.         }
  15.         printf("\n");
  16.     }
  17.  
  18.     int count = 0;
  19.  
  20.     for(int i = 0; i < n + count; i++) {
  21.         int nulls = 0;
  22.         for(int j = 0; j < n; j++)
  23.             if (a[j][i] == 0)
  24.                 nulls++;
  25.  
  26.         if (nulls > 0) {
  27.             for(int k = n + 1; k > i + 1; k--)
  28.                 for(int l = 0; l < n; l++)
  29.                     a[l][k] = a[l][k - 1];
  30.  
  31.             for(int m = 0; m < n; m++)
  32.                 a[m][i + 1] = 0;
  33.  
  34.             stol++;
  35.             ++i;
  36.             ++count;
  37.         }
  38.     }
  39.  
  40.     printf("\n");
  41.  
  42.     for(int i = 0; i < n; i++) {
  43.         for(int j = 0; j < n + stol; j++) {
  44.             printf("%d\t", a[i][j]);
  45.         }
  46.         printf("\n");
  47.     }
  48.  
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement