Little secret of the two-dimensional array of matrix inversion so easy

Write your own matrix (two-dimensional array), himself upside down

I believe learned linear algebra little friends all know that the matrix is that it's the source of all evil, and matrix inversion is one of a small test sites
so today, I will come and we try together with the c language to solve this problem, you need input data, the computer will automatically help you transposed matrix, is not very interesting ah?
Of course, the relevant test sites involved in this process today is the application of two-dimensional array of friends, we work together to learn it!

#include<stdio.h>
int main()
{
	int tdarr1[2][3], tdarr2[3][2];
	int i, j;
	for ( i = 0; i < 2; i++)
	{
		for (j = 0; j < 3; j++)
		{
			printf("tdarr1[%d][%d]=", i, j);
			scanf_s("%d", &tdarr1[i][j]);
			printf("\n");
		}
	}
	printf("您刚刚输入的二维数组是:\n");
	for (i = 0; i < 2; i++)
	{
		for (j = 0; j < 3; j++)
		{
			printf("%d\t", tdarr1[i][j]);
		}
		printf("\n");
	}
	printf("现在我们要将该数组倒置:\n");

	for (i = 0; i < 2; i++)
	{
		for (j = 0; j < 3; j++)
		{
			tdarr2[j][i] = tdarr1[i][j];
		}
	}
	printf("\n");
	puts("下面我们将输出倒置之后的二维数组:\n");
	for (i= 0; i< 3; i++)
	{
		for (j = 0; j < 2; j++)
		{
			printf("%d\t", tdarr2[i][j]);
		}
		printf("\n");
	}
	return 0;
}

Of course, you can also put the number of rows and columns of the array changes a bit, you can get more and larger arrays it!
Come on everybody!

Like me, then give a pair of praise, thank you for the support you, this afternoon I was just written the code, hey!

Released seven original articles · won praise 9 · views 3460

Guess you like

Origin blog.csdn.net/weixin_46253007/article/details/104199730