矩阵旋转90度 写好了 大家帮我指一下缺陷
是n*m的程序代码:
#include"stdio.h" #define N 10 void main() { //0 is current_array,1 is rotated_array int arr[2][N][N],i,j,arr_col,arr_row,dim_x,dim_y,temp=0; printf("please input the dim:(the format is dim1 * dim2)\n"); scanf("%d*%d",&dim_x,&dim_y);//input the dim for(i=0;i<dim_x;i++) //init the array for(j=0;j<dim_y;j++) arr[0][i][j]=++temp; printf("the current array:\n"); for(i=0;i<dim_x;i++) //output the array { for(j=0;j<dim_y;j++) printf("%6d",arr[0][i][j]); printf("\n"); } arr_col=dim_x-1; for(i=0;i<dim_x;i++)//rotate the arr_current,resemble the stack { arr_row=0; for(j=0;j<dim_y;j++) { arr[1][arr_row][arr_col]=arr[0][i][j]; arr_row++; } arr_col--; } printf("the rotated array by 90 angle :\n"); for(i=0;i<dim_y;i++) //output the arr_rotated { for(j=0;j<dim_x;j++) printf("%6d",arr[1][i][j]); printf("\n"); } }
[[it] 本帖最后由 zmhdxy 于 2008-4-3 10:18 编辑 [/it]]