i have been trying all day!!!

actually i made it but i need to do it in a different way... u see..

Code:

if(MatWid < MatHei) {
Layers = MatWid / 2;
}
else
Layers = MatHei / 2;
/* According to the number of circulations required */
for (circ = 0 ; circ < numOfCir ; circ++)
{
/* According to the number of layers */
for (layer = 0 ; layer < Layers ; layer++)
{
int tmp1, tmp2;
/* Save upper right corner */
tmp1 = Matrix[layer][MatWid-layer-1];
/* Upper bound */
for (j = MatWid-layer-2 ; j >= layer ; j--)
{
Matrix[layer][j+1] = Matrix[layer][j];
}
/* Save bottom right corner */
tmp2 = Matrix[MatHei-layer-1][MatWid-layer-1];
/* Right bound */
for (i = MatHei-layer-2 ; i >= layer ; i--)
{
if (i != layer)
Matrix[i+1][MatWid-layer-1] = Matrix[i][MatWid-layer-1];
else
Matrix[i+1][MatWid-layer-1] = tmp1;
}
/* Save bottom left corner */
tmp1 = Matrix[MatHei-layer-1][layer];
/* Bottom bound */
for (j = layer ; j < MatWid-layer-1 ; j++)
{
if (j != MatWid-layer-2)
Matrix[MatHei-layer-1][j] = Matrix[MatHei-layer-1][j+1];
else
Matrix[MatHei-layer-1][j] = tmp2;
}
/* Left bound */
for (i=layer; i<MatHei-layer-1; i++)
{
if (i != MatHei-layer-2)
Matrix[i][layer] = Matrix[i+1][layer];
else
Matrix[i][layer] = tmp1;
}
}
}