Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define true 1
- #define false 0
- #define rows 4
- #define cols 3
- int all1(int arr[][3])
- {
- int i,k;
- for(i=0;i<rows;i++)
- for(k=0;k<cols;k++)
- if(arr[i][k]!=1)
- return false;
- return true;
- }
- int main()
- {
- char matrix[4][3]= { {'1','2','3'} , {'4','5','6'} , {'7','8','9'} , {'a','b','c'}};
- int arr[rows][cols]={0};
- int x=0,y=0,a=1;
- while(!all1(arr))
- {
- if(arr[y][x]!=1)
- printf ("%c \n",matrix[y][x]);
- arr[y][x]=1;
- switch (a )
- {
- case 1: //ימינה עד הסוף
- if(x<cols-1&&arr[y][x+1]!=1)
- x++;
- else
- a++;
- break;
- case 2: //למטה עד הסוף
- if (y<rows-1&&arr[y+1][x]!=1&&a==2)
- y++;
- else
- a++;
- break;
- case 3: //שמאלה עד הסוף
- if(x>0&&arr[y][x-1]!=1)
- x--;
- else
- a++;
- break;
- case 4://למעלה עד הסוף
- if (y>0&&arr[y-1][x]!=1)
- y--;
- else
- a=1;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement