#include
void fun( int*,size_t );
void swap( int*,int* );
void print( const int*,size_t,size_t );
int main( void )
{
int arr[][3]=
{
{1,2,3},
{4,5,6},
{7,8,9}
};
const size_t size=sizeof (arr)/sizeof (*arr);
fun(*arr,size);
print(*arr,size,size);
return 0;
}
void fun( int* arr,size_t size )
{
size_t i=0;
size_t j=1;
if (size==0)
return ;
for (;i!=size-1;++j!=size?1:(j=++i+1))
swap(arr+size*i+j,arr+size*j+i);
}
void swap( int* p,int* q )
{
const int t=*p;
*p=*q;
*q=t;
}
void print( const int* arr,size_t col,size_t row )
{
const size_t size=(col+1)*row;
size_t i;
for (i=0;i!=size;++i)
{
const size_t m=i%(row+1);
const size_t n=col*(i/col)+i%row-i/(row+1);
printf("%-4d\000\n"+5*(m==row),*(arr+n));
}
}