轉置矩陣練習:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int x,y;
int i,j;
printf("please input the row of matrix :");
scanf("%d",&x);
printf("\n");
printf("please input the column of matrix : ");
scanf("%d",&y);
printf("\n");
int matrix[x+1][y+1];
int t_matrix[y+1][x+1];
for(i=0;i<=(x-1);i++)
{
for(j=0;j<=(y-1);j++)
{
printf("please int the value of matrix[%d][%d]:\t",i,j);
scanf("%d",&matrix[i][j]);
printf("\n");
}
}
printf("The original matrix[%d][%d] is:\n",x,y);
for(i=0;i<=(x-1);i++)
{
for(j=0;j<=(y-1);j++)
{
t_matrix[j][i]= matrix[i][j];
printf("%d\t",matrix[i][j]);
}
printf("\n");
}
printf("The transverse matrix[%d][%d] is:\n",y,x);
for(i=0;i<=(y-1);i++)
{
for(j=0;j<=(x-1);j++)
{
printf("%d\t",t_matrix[i][j]);
}
printf("\n");
}
system("pause");
}
沒有留言:
張貼留言