C语言:二维数组中最大值及行号列号

#include <stdio.h>
//求二维数组中的最大值及对应的行号与列号 
main()
{
    int a[5][5]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,24,15,16,21,17,18,19,20,22,23} ,max,hang,lie,c,b;
    max=a[0][0];
    for(c=0;c<=4;c++)
    for(b=0;b<5;b++)
    {
        if(max< a[c][b]) 
        {
            max=a[c][b];
            hang=c;
            lie=b;
        }        
    }
    printf("最大值为:%d,所在行:%d,所在列:%d",max,hang,lie);


    getchar();
}
#include <stdio.h>
//最大值有多个,分别输出对应在的行号与列号 
main()
{
    int a[5][5]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,24,24,15,16,21,17,18,19,24,22,23} ,max,hang,lie,c,b;
    int hanga[25],liea[25],count=0,v;
    max=a[0][0];v=max;
    for(c=0;c<=4;c++)
    for(b=0;b<5;b++)
    {
        if(max< a[c][b]) 
        {
            max=a[c][b];
        }
    }
    printf("最大值为:%d\n",max);//24
    for(c=0;c<=4;c++)
    for(b=0;b<5;b++)
    {
        if(max==a[c][b]) hanga[count]=c,liea[count]=b,count++;
    }
    for(c=0;c<count;c++)
    printf("行:%d,列:%d\n",hanga[c],liea[c]);
    getchar();
}

 

原文链接: https://www.cnblogs.com/xkdn/p/17128099.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    C语言:二维数组中最大值及行号列号

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/318438

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月17日 上午9:33
下一篇 2023年2月17日 上午9:33

相关推荐