Fork me on GitHub

P_154找出已知矩阵中最大元素值,及所在位置

 1 //找出矩阵中最大元素值,及所在位置 
 2 #include<iostream>
 3 #include<string.h>
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     int i,j,row=0,col=0,max;
 9     int a[3][4]={{1,2,3,4},{9,8,7,6},{-10,10,-5,2}};
10     max=a[0][0];
11     for(i=0;i<=2;i++)
12     {
13         for(j=0;j<=3;j++)
14         {
15             if(a[i][j]>max)//找到比前一个大的值,将它赋值 
16             {
17                 max=a[i][j];
18                 row=i;
19                 col=j;
20             }
21         }
22     }
23     cout<<max<<endl<<row<<endl<<col<<endl;
24     return 0;
25 }
26 //字符处理函数 
27 /*int main()
28 {
29     char str[]="China ";
30     char str1[]="my HOME";
31     cout<<strcpy(str1,str)<<endl;
32     cout<<strlwr(str)<<endl;//大写转小写 
33     cout<<strupr(str)<<endl;//小写转大写 
34     cout<<strlen(str)<<endl;
35     cout<<strcat(str,str1)<<endl;//连接字符 
36     return 0;
37 }*/

 

posted @ 2018-04-10 15:21  风中等待  阅读(345)  评论(0)    收藏  举报