/输入一个正整数n (1≤ n ≤6),再输入一个n 行n列的矩阵,找出该矩阵中绝对值最大的元素以及它的行下标和列下标。/
#include <stdio.h>
void fun(void)
{
int n, i, j;
int max_val = 0, max_row = 0, max_col = 0;
printf("please enter number,1<=number<=6\n");
scanf("%d", &n);
int matrix[n][n];
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
printf("please enter matrix[%d][%d]\n", i+1, j+1);
scanf("%d", &matrix[i][j]);
if (i == 0 && j == 0)
{
max_val = matrix[i][j];
}
else if (matrix[i][j] > max_val)
{
max_val = matrix[i][j];
max_row = i;
max_col = j;
}
}
}
// 输出结果
printf("max:%d\n", max_val);
printf("Row subscript:%d Line subscript:%d\n", max_row, max_col);
}
int main(void)
{
fun();
return 0;
}
标签:下标,val,int,max,矩阵,输入
From: https://www.cnblogs.com/yesiming/p/18297382