有一个3*3的整型二维数组,写一个函数,当主函数调用此函数后,能求出平均值、最大值和最小值.如题,是C语言

来源:学生作业帮助网 编辑:作业帮 时间:2024/06/06 10:08:00
有一个3*3的整型二维数组,写一个函数,当主函数调用此函数后,能求出平均值、最大值和最小值.如题,是C语言
xUmk@*GiTL7~ߍ2I^CôB݆E*` XŽ4-$wif S!ߥ*ǃxp0ywOƧ;ቻ۟ !y: uA2z9 cߚ:t< [#&青_~}wG:'/vyȇw|wz|4=Oi r%Ցpi-QElX ͷHPv,ׁ4j!I-Ⱥe;ښT)u DB>P6^sC/sЃ$/=oAyA a= `>hJ`\`-xp:o#3,b9]fCX/aA2OLn(UńmH !8R~J-cT\5FV9d8vo|{7s ;LN}1*.G%4s/>iTԄf(b y5þ!L,5<dK%6+4,\>joN<r" }.t\K{'C nI" AW`G8&뵿.DgL 煛:)2+2 P _@IzZ"

有一个3*3的整型二维数组,写一个函数,当主函数调用此函数后,能求出平均值、最大值和最小值.如题,是C语言
有一个3*3的整型二维数组,写一个函数,当主函数调用此函数后,能求出平均值、最大值和最小值.
如题,是C语言

有一个3*3的整型二维数组,写一个函数,当主函数调用此函数后,能求出平均值、最大值和最小值.如题,是C语言
#include &lt;iostream&gt;
using namespace std;
void num_calc(int array[3][3],double &amp; aver_num,int &amp; max_num,int &amp; min_num);
int main()
{
int a[3][3] = { 1,2,3,
7,8,9,
4,5,6 };
int max_num,min_num;
double aver_num;

num_calc(a,aver_num,max_num,min_num);

// print the number,you also can use "printf" with library stdio.h included.
cout &lt;&lt; "The average number is:" &lt;&lt; aver_num &lt;&lt; endl;
cout &lt;&lt; "The max number is:" &lt;&lt; max_num &lt;&lt; endl;
cout &lt;&lt; "The min number is:" &lt;&lt; min_num &lt;&lt; endl;
}
void aver_calc(int array[3][3],double &amp; aver_num)
{
int sum = 0;
for(int i = 0; i &lt; 3; i++)
for(int j = 0; j &lt; 3; j++)
{
sum += array[i][j];
}
aver_num = sum / 9.0;
}
void max_calc(int array[3][3],int &amp; max_num)
{
max_num = array[0][0];
for(int i = 0; i &lt; 3; i++)
for(int j = 0; j &lt; 3; j++)
{
if(max_num &lt; array[i][j])
max_num = array[i][j];
}
}
void min_calc(int array[3][3],int &amp; min_num)
{
min_num = array[0][0];
for(int i = 0; i &lt; 3; i++)
for(int j = 0; j &lt; 3; j++)
{
if(min_num &gt; array[i][j])
min_num = array[i][j];
}
}
void num_calc(int array[3][3],double &amp; aver_num,int &amp; max_num,int &amp; min_num)
{
aver_calc(array,aver_num);
max_calc(array,max_num);
min_calc(array,min_num);
}