Advertisement
Lisaveta777

Ответы 3

Apr 25th, 2022 (edited)
889
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.13 KB | None | 0 0
  1. //https://otvet.mail.ru/question/228893262
  2. #include <stdio.h>
  3.  
  4.  
  5. int main()
  6. {
  7.     int i,j,n, m,k=1 ;
  8.     n = 5; m = 4;
  9.    
  10.     int arr[m][n];
  11.     for(i=0;i<m;i++)//fill an array
  12.     {
  13.         for(j=0;j<n;j++)
  14.         {
  15.             arr[i][j] = k++;
  16.         }
  17.     }
  18.     printf("%d\n",arr[3][2]);
  19.    
  20.     printf("ARRAY BEFORE SORTING:\n");  
  21.     for(i=0;i<m;i++)//print an array
  22.     {
  23.         for(j=0;j<n;j++)
  24.         {
  25.             printf("%d\t",arr[i][j]);
  26.         }
  27.         printf("\n");
  28.     }
  29.    
  30.     for(i=0;i<m;i++)//move elements forward
  31.     {
  32.         for(j=0;j<n;j++)
  33.         {
  34.             if((i!=m)&&(j!=n))//all rows exepts last, all columns exept last
  35.             {
  36.                arr[i][j]= arr[i][j+1];
  37.             }
  38.             else //fill last element in each row
  39.             {
  40.                 arr[i][j] = arr[i+1][0];
  41.             }
  42.            
  43.         }
  44.     }
  45.     printf("ARRAY AFTER SORTING:\n");  
  46.     for(i=0;i<m;i++)//print an array
  47.     {
  48.         for(j=0;j<n;j++)
  49.         {
  50.             printf("%d\t",arr[i][j]);
  51.         }
  52.         printf("\n");
  53.     }  
  54.    
  55.  
  56.     return 0;
  57. }
  58.  
  59.  
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement