Contest100000569 - 《算法笔记》2.5小节——问题 I: 例题6-4 矩阵转置

本文详细介绍了一个2行3列矩阵如何通过行列互换转换为3行2列矩阵的过程,包括输入输出示例及C语言实现代码。

问题 I: 例题6-4 矩阵转置

题目描述

将一个2行3列的矩阵(二维数组)行列互换,存储到另一个3行2列的矩阵中。

要求以整型数据为例来解答。

输入

输入2行数据,每行3个整数,以空格分隔。

输出

行列互换后的矩阵,3行,每行2个数据,以空格分隔。

样例输入

1 2 3
4 5 6

样例输出

1 4
2 5
3 6

提示:

该题用一个一维数组或是一个二维数组就能轻易实现,但按照题意须用到数组转置,故参考代码使用两个二维数组实现。

参考代码:

# include<stdio.h>

int main()
{	
	int arr1[2][3] = {0};
	int arr2[3][2] = {0};
	int i, j;
	for(i = 0; i < 2; ++i)
	{
		for(j = 0; j < 3; ++j)
		{
                    scanf("%d", &arr1[i][j]);
		}
	}
			
	for(i = 0; i < 2; ++i)
	{
		for(j = 0; j < 3; ++j)
		{
			arr2[j][i] = arr1[i][j];
		}
	}
	
	for(i = 0; i < 3; ++i)
	{
		for(j = 0; j < 2; ++j)
		{
			printf("%d ", arr2[i][j]);
		}
		printf("\n");
	}
	return 0;
}

 

你针对这部分修改,为避免式改变 把式代码也修改:.csw-h5-contest-racesSlots { padding: 12px 24px 0; .csw-opensource-h5-learningHeader { height: 24px; width: 100%; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; .csw-opensource-h5-learningHeader-title { color: rgb(0, 0, 0); font-size: 18px; font-weight: 500; line-height: 20px; } .csw-opensource-h5-learningHeader-more { color: rgb(153, 153, 153); font-size: 12px; font-weight: 400; line-height: 16px; .csw-opensource-h5-learningHeader-moreText { padding-right: 4px; } } } .csw-h5-contest-racesSlots-content { position: relative; .adm-jumbo-tabs-header { border: 0; .adm-jumbo-tabs-tab-list { padding: 0; .adm-jumbo-tabs-tab-wrapper { flex: none; padding: 0; margin-right: 16px; .adm-jumbo-tabs-tab { font-weight: 500; color: rgb(102, 102, 102); padding: 0; } .adm-jumbo-tabs-tab-active { color: rgb(0, 65, 211); } } } } .adm-jumbo-tabs-content { padding: 16px 0 12px; } .csw-h5-contest-topSummitsCarousel { width: 100%; padding-bottom: 12px; .topSummitsList { display: flex !important; justify-content: space-between; .topSummitsItem { width: 48%; position: relative; img { width: 100%; aspect-ratio: 1.785; border-radius: 4px; } .mask { width: 100%; height: 100%; position: absolute; bottom: 0; border-radius: 4px; } .maskCourse { position: absolute; top: 6px; right: 6px; display: inline-block; height: 20px; text-align: center; line-height: 20px; padding: 2px 8px 2px 8px; border-radius: 53px; background: rgba(0, 65, 211, 0.7); color: rgb(255, 255, 255); font-size: 11px; font-weight: 400; line-height: 16px; } .topSummitsItemTitle { display: inline-block; margin-top: 8px; width: 100%; color: rgb(0, 0, 0); font-weight: 400; line-height: 24px; } .itemSubTitle { font-family: HarmonyHeiTi; color: #666666; font-size: 12px; font-weight: 400; line-height: 19px; } } } .slick-dots-bottom { bottom: 3px; z-index: 9; li { height: 2px !important; width: 6px !important; } button { width: 6px !important; background: #f2f2f2 !important; opacity: 1 !important; border-radius: 30px !important; height: 2px !important; } .slick-active { width: 12px !important; border-radius: 1px !important; button { background-color: rgb(0, 65, 211) !important; width: 12px !important; } } } } .csw-racesSlots-h5-more { color: rgb(153, 153, 153); font-size: 12px; font-weight: 400; line-height: 16px; position: absolute; right: 0; top: 17px; .anticon-right { margin-left: 3px; } } .moreDomCss { position: absolute; top: 4px; right: 0; color: rgb(153, 153, 153); font-size: 12px; font-weight: 400; line-height: 16px; .moreText { padding-right: 4px; } } } }
最新发布
11-21
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值