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;
}

  

转载于:https://www.cnblogs.com/ailx10/p/5337131.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值