Advertisement
KrimsN

Untitled

Nov 8th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <locale.h>
  4. #include <time.h>
  5.  
  6. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  7.  
  8. int main(int argc, char *argv[]) {
  9.     setlocale(LC_ALL , "rus");
  10.     srand(time(NULL));
  11.     int **x;
  12.     int i, j, n, k=0;
  13.     printf("N - ยป: ");
  14.     scanf("%d", &n);
  15.     printf("\n");
  16.  
  17.     x=(int**)malloc(sizeof(int*)*n);
  18.     for(i=0; i<n; i++){
  19.         x[i]=(int*)malloc(sizeof(int)*n);
  20.     }
  21.  
  22.  
  23.     for (i=0; i<n; i++){
  24.         for (j=0; j<n; j++){
  25.             x[i][j]=rand()%20 - 10;
  26.         }
  27.     }
  28.  
  29.  
  30.     for (i=0; i<n; i++){
  31.         for (j=0; j<n; j++){
  32.             printf("%3d ", x[i][j]);
  33.         }
  34.         printf("\n");
  35.     }
  36.     int count = 0;
  37.     printf("\n");
  38.  
  39.     int m=n;
  40.     for(int i =0;i<m-1;i++){
  41.         if(x[n-1][i]>0){
  42.             for(int j_1 = i; j_1 < m-1; j_1++)
  43.                 for(int j=0;j<n;j++){
  44.                     x[j][j_1]=x[j][j_1+1];
  45.                     x[j][j_1+1] = 375;
  46.                 }
  47.             if(x[0][i] != 375)
  48.                 m--;
  49.             i--;
  50.         }
  51.     }
  52.      
  53.     x = (int**)realloc(x , sizeof(int*) * m);
  54.     printf("\n");
  55.  
  56.     for (i=0; i<n; i++){
  57.         for (j=0; j<m; j++){
  58.             printf("%3d ", x[i][j]);
  59.         }
  60.         printf("\n");
  61. }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement