Advertisement
Lisaveta777

Zmeika

Nov 6th, 2018
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 0 0
  1. //https://otvet.mail.ru/question/211343438
  2. //populate array with values 1,2..., quite exotic order
  3. //print the following:
  4. // 0  0  0  0  0  0  0  0  0
  5. // 1  0  0  0  0  0  0  0 26
  6. // 2  8  0  0  0  0  0 21 27
  7. // 3  9 13  0  0  0 18 22 28
  8. // 4 10 14 16  0 17 19 23 29
  9. // 5 11 15  0  0  0 20 24 30
  10. // 6 12  0  0  0  0  0 25 31
  11. // 7  0  0  0  0  0  0  0 32
  12. // 0  0  0  0  0  0  0  0  0
  13.  
  14.  
  15. #include <stdio.h>
  16.  
  17. #define NINE 9
  18.  
  19. int main()
  20. {
  21.    int i,j,counter,gap,top=0;
  22.    int arr3[NINE][NINE]={0};
  23.    counter = gap = 1;
  24.  
  25.    for(j=0;j<NINE;j++)
  26.    {
  27.  
  28.        for(i=gap;i<NINE-gap;i++)
  29.        {
  30.            arr3[i][j]=counter++;
  31.        }
  32.  
  33.  
  34.  
  35.         if(top||gap==5)//gap decreases from now on
  36.         gap--,top++;
  37.         else if(gap<5)//gap increases here
  38.         gap++;
  39.  
  40.  
  41.    }
  42.    for(i=0;i<NINE;i++)
  43.    {
  44.        for(j=0;j<NINE;j++)
  45.         printf("%4d",arr3[i][j]);
  46.        printf("\n");
  47.    }
  48.  
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement