3*4的矩阵,编程求出其中最大值,以及其所在的行号和列号。

#include<iostream>
using namespace std;
int main(){
	int array[3][4]={{1,46,98,-4},
			         {45,22,-75,0},
			         {456,498,35,4}};		         
	int unknow=array[0][0];	 
	int h=0;
	int l=0;       
	for(int i=0;i<3;i++){
		for(int j=0;j<4;j++){
			if(array[i][j]>unknow){
				unknow=array[i][j];
				h=i;
				l=j;
			}
		}
	}		    
	cout<<"¶þάÊý×é×î´óÖµ"<<unknow<<" ËùÔÚÐÐ "<<h+1<<"ËùÔÚÁÐ "<<l+1<<endl;
     
}

  

 

#include<iostream>
using namespace std;

int MAXY(int array[3][4]){
	int unknow=array[0][0];	 
	int h=0;
	int l=0;       
	for(int i=0;i<3;i++){
		for(int j=0;j<4;j++){
			if(array[i][j]>unknow){
				unknow=array[i][j];
				h=i;
				l=j;
			}
		}
	}cout<<"¶þάÊý×é×î´óÖµ"<<unknow<<" ËùÔÚÐÐ "<<h+1<<"ËùÔÚÁÐ "<<l+1<<endl;
	}
int main(){
	int array[3][4]={{1,46,98,-4},
			         {45,22,-75,0},
			         {456,498,35,4}};
    MAXY(array);					 		         	    
}

  

 

posted on 2017-11-27 21:34  三叶癌  阅读(444)  评论(0编辑  收藏  举报

导航