用数组元素做函数实参

来源:互联网 发布:机械制图软件手机版 编辑:程序博客网 时间:2024/06/06 00:35
/** 程序的版权和版本声明部分* Copyright  (c)2013,烟台大学计算机学院学生* All rightsreserved.* 文件名称:array.cpp* 作者:张凯* 完成日期;: 2013年12月5日* 版本号: v1.0* 输入描述: 无* 问题描述:用数组做函数求3*4矩阵的最大值*/#include <iostream>using namespace std;int max_value(int x,int max); //函数声明int main(){    int i,j,row=0,colum=0,max;//row代表行数(i),colum代表列数(j)    int a[3][4]={{-1,5,96,6},{69,0,56,2},{89,123,17,98}};    max=a[0][0];    for(i=0;i<3;i++)    for(j=0;j<4;j++)    {        max=max_value(a[i][j],max);        if(max==a[i][j])        row=i;        colum=j;    }    cout<<"max="<<max<<",row="<<row<<",colum="<<colum<<endl;    return 0;}int max_value(int x,int max){    if(x>max)    return x;    else    return max;}

运行结果 (如下图)

                                

心得体会:上课听不太透彻的,通过实例可能就会突然明白。

原创粉丝点击