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