44.从键盘输入12个数存入二维数组a[3][4]中,编写程序求出最大元素的值及它所在的行号和列号

//1、建立二维数组
//2、运用循环,将内容输入到数组中
//3、求出最大元素,并输出行号和列号

#include<iostream>
using namespace std;

int main()
{
    int a[3][4];
    int Max=0;//赋值之前需要先置为0
    cout<<"please input 12 numbers: "<<endl;
    for(int i=0;i<3;i++)//嵌套循环,用于向二维数组中输入内容
    {
        for(int j=0;j<4;j++)
        {
            cin>>a[i][j];
        }
    }

    for(int m=0;m<3;m++)//用于判断数组中的最大元素是多少
    {
        for(int n=0;n<4;n++)
        {
            if(a[m][n]>=Max)
            {
                Max=a[m][n];
            }
        }
    }
    cout<<"the biggest number is "<<Max<<endl;


    for(int p=0;p<3;p++)//用于判断最大元素所在的位置
    {
        for(int q=0;q<4;q++)
        {
            if(Max==a[p][q])
            {
                cout<<"它在第"<<p+1<<"行,"<<""<<q+1<<""<<endl;
            }
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/jixiaowu/p/3899928.html