11 12 13 14
15 16 17 18
19 20 21 22
23 24 25 26
then output should be...
11 12 13 14 18 22 26 25 24 23 19 15 16 17 21 20
This program can be done by difffernt ways matter is of complexity..
so do post ur ideas.....
x=y=0;
dir=RIGHT;
printf ("\nEnter the order:");
scanf ("%d",&n);
printf ("\nEnter the matrix\n");
for (i=0;i<n;i++)
for (j=0;j<n;j++)
scanf ("%d",&matrix[i][j]);
lrb=n;
dub=n-1;
turnx=0;
turny=1;
sqn=n*n;
for (i=0;i<sqn;i++)
{
printf (" %d",matrix[x][y]);
switch(dir)
{
case 0:
y++;
turny++;
if (turny==lrb)
{
dir=3;
lrb--;
turny=0;
}
break;
case 1:
y--;
turny++;
if (turny==lrb)
{
dir=2;
lrb--;
turny=0;
}
break;
case 2:
x--;
turnx++;
if (turnx==dub)
{
dir=0;
dub--;
turnx=0;
}
break;
case 3:
x++;
turnx++;
if(turnx==dub)
{
dir=1;
dub--;
turnx=0;
}
break;
}
}
return 0;
Do tell me if i am wrong somewhere or missed a trick..
Ciao,
Ajinkya.
> - Hide quoted text -
>
> - Show quoted text -