2022
选出m行n列数组中 绝对值最大的数 和 其坐标
因为只选择最大的绝对值 所以没有用数组
#include <stdio.h> #include <math.h> int main() { int m, n, s, i, j, t, max, lin, col; while (scanf_s("%d%d", &m, &n)) { t = max = 0; for (i = 0;i < m; i++) { for (j = 0; j < n; j++) { scanf_s("%d",&s); if (abs(s) > abs(max)) { t = s; s = max; max = t; lin = i; col = j; } } } printf("%d %d %d\n",lin + 1,col + 1,max); } return 0; }
参考答案
#include <math.h> #include <stdio.h> int main(void) { int i, j; int n, m; int x, y; double a, t; while (scanf("%d%d", &n, &m) != EOF) { a = x = y = 0; for (i = 0 ; i < n ; i++) { for (j = 0 ; j < m ; j++) { scanf("%lf", &t); if (fabs(t) > fabs(a)) { a = t; x = i; y = j; } } } printf("%d %d %.0f\n", x + 1, y + 1, a); } return 0; }
========================if i have some wrong, please give me a message, thx.========================