C程序对矩阵的所有列和行进行排序
问题
编写代码,将矩阵的所有行按升序排序,将所有列按降序排序。矩阵的大小和矩阵的元素由用户在运行时给出。
解决方案
下面解释了在C编程语言中按升序对矩阵的所有行和所有列按降序进行排序的解决方案-
用于按升序对行进行排序的逻辑如下-
for (i=0;ima[i][k]){ a = ma[i][j]; ma[i][j] = ma[i][k]; ma[i][k] = a; } } } }
用于按降序对列进行排序的逻辑如下-
for (j=0;j程序
以下是按升序对矩阵的所有行和按降序对所有列进行排序的C程序-
#includevoid main(){ int i,j,k,a,m,n; static int ma[10][10],mb[10][10]; printf ("Enter the order of the matrix \n"); scanf ("%d %d", &m,&n); printf ("Enter co-efficients of the matrix \n"); for (i=0;i ma[i][k]){ a = ma[i][j]; ma[i][j] = ma[i][k]; ma[i][k] = a; } } } } for (i=0;i 输出结果 执行上述程序时,会产生以下结果-
Enter the order of the matrix 3 4 Enter co-efficient of the matrix 1 2 3 4 1 2 3 4 5 1 2 3 The given matrix is 1 2 3 4 1 2 3 4 5 1 2 3 After arranging rows in ascending order 1 2 3 4 1 2 3 4 1 2 3 5 After arranging the columns in descending order 5 2 3 4 1 2 3 4 1 1 2 3
热门推荐
10 病人祝福语老师寄语简短
11 新娘生孩子祝福语简短
12 婆婆66岁祝福语简短
13 今天孩子高考祝福语简短
14 送彩票生日祝福语简短
15 分别祝福语简短情话英文
16 画室揭牌仪式祝福语简短
17 女友妈妈生日祝福语简短
18 离别赠言离职祝福语简短