Hi friends.

There's something wrong with my code. I want to shift each row one place upwards. The following square matrix of size 5 should look like this after the rotation.

e f g h x

i j k l x

m n o p x

q r s t x

a b c d x

Any help is appreciated.

Code:

#include<stdio.h>
#define SIZE 5
int main()
{
char a[SIZE][SIZE] =
{
{'a','b','c','d','x'},
{'e','f','g','h','x'},
{'i','j','k','l','x'},
{'m','n','o','p','x'},
{'q','r','s','t','x'}
};
int i, j;
char temp[SIZE][SIZE];
for(i=0;i<SIZE;i++)
{
for(j=0;j<SIZE;j++)
printf("%c", a[i][j]);
printf("\n");
}
printf("\n\n");
for(i=0;i<SIZE;i++) // reverse_count necessary here!!
for(j=0;j<SIZE;j++)
{
if (i==SIZE) //check_the last_row
{
for(j=0;j<SIZE;j++)
temp[i][j]= a[i][j];
a[i][j]= a[1][j];
a[1][j] =temp[i][j];
}
temp[i][j]= a[i][j]; // initializing
a[i][j]= a[i/(SIZE-1)+1][j]; // change a[i][j] into its new value
a[i/(SIZE-1)+1][j] =temp[i][j];
}
/* for(i=0;i<SIZE;i++){ // reverse_count necessary here!!
for(j=0;j<SIZE;j++)
{
temp[i][j]= a[i][j]; // initializing
a[i][j]= a[i/3+1][j] ; // change a[i][j] into its new value
a[i/3+1][j] =temp[i][j];
}
}
*/
//--------------------
for(i=0;i<SIZE;i++)
{
for(j=0;j<SIZE;j++)
printf("%c", a[i][j]);
printf("\n");
}
return 0;