zoukankan      html  css  js  c++  java
  • 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
    ",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
    ", x + 1, y + 1, a);
        }
    
        return 0;
    }
    

      

    ========================if i have some wrong, please give me a message, thx.========================
  • 相关阅读:
    java工程师要求
    系统架构设计师知识模块
    Mybatis使用训练
    项目—视频直播系统
    [数算]概率
    查看镜像文件
    Hadoop启动命令
    Hadoop启动命令
    HDFS设置配额管理
    HDFS设置配额管理
  • 原文地址:https://www.cnblogs.com/ailx10/p/5337131.html
Copyright © 2011-2022 走看看