提交时间:2019-12-16 20:00:49
运行 ID: 3405
#include <stdio.h> #include <stdlib.h> //函数声明 //函数原型: void input_matrix(int a[][100],int n); //-------------------------------------------------------------- // 功能:输入方阵数据 //参数:[int a[][100]] ---方阵 // [int n] --- 方阵大小 //-------------------------------------------------------------- //函数原型: void transpose(int a[][100],int n); //-------------------------------------------------------------- // 功能:方阵数据转置 // 参数:[int a[][100]] ---方阵 // [int n] --- 方阵大小 //-------------------------------------------------------------- //函数原型: void max_pos(int a[][100],int n); //------------------------------------------------------------ // 功能:求取最大值元素坐标及最大值元素 // 参数:[int a[][100]] ---方阵 // [int n] --- 方阵大小 //-------------------------------------------------------------- //函数原型: void output_matrix(int a[][100],int n); //-------------------------------------------------------------- // 功能:输出方阵数据 // 参数:[int a[][100]] ---方阵 // [int n] --- 方阵大小 //-------------------------------------------------------------- int main() { int n,a[100][100]; scanf("%d",&n); input_matrix(a,n); transpose(a, n); output_matrix(a,n); max_pos(a,n); return 0; } void input_matrix(int a[][100],int n) { for (int i = 0; i < n; i++){ for (int j = 0; j < n; j++){ scanf("%d",&a[i][j]);//输入数组的值 } } } void transpose(int a[][100],int n) { int temp; for (int i = 0; i < n; i++){ for (int j = 0; j < i; j++){ temp = a[i][j]; a[i][j] = a[j][i]; a[j][i] = temp; } } } void max_pos(int a[][100],int n) { int Maxx = a[0][0]; int p = 0, q = 0; for (int i = 0; i < n; i++){ for (int j = 0; j < n; j++){ if (Maxx < a[i][j]){ Maxx = a[i][j]; p = i; q = j; } } } printf("%d %d %d\n",p,q,Maxx); } void output_matrix(int a[][100],int n) { for (int i = 0; i < n; i++){ for (int j = 0; j < n; j++){ printf("%d ",a[i][j]); } printf("\n"); } }