有一个3*3的整型二维数组,写一个函数,当主函数调用此函数后,能求出平均值、最大值和最小值.如题,是
答案:2 悬赏:30 手机版
解决时间 2021-02-13 13:24
- 提问者网友:骨子里的高雅
- 2021-02-13 03:53
有一个3*3的整型二维数组,写一个函数,当主函数调用此函数后,能求出平均值、最大值和最小值.如题,是
最佳答案
- 五星知识达人网友:洒脱疯子
- 2021-02-13 04:30
#include <iostream>using namespace std;void num_calc(int array[3][3],double & aver_num,int & max_num,int & 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 << The average number is: << aver_num << endl;cout << The max number is: << max_num << endl;cout << The min number is: << min_num << endl;}void aver_calc(int array[3][3],double & aver_num){int sum = 0;for(int i = 0; i < 3; i++)for(int j = 0; j < 3; j++){sum += array[i][j];}aver_num = sum / 9.0;}void max_calc(int array[3][3],int & max_num){max_num = array[0][0];for(int i = 0; i < 3; i++)for(int j = 0; j < 3; j++){if(max_num < array[i][j])max_num = array[i][j];}}void min_calc(int array[3][3],int & min_num){min_num = array[0][0];for(int i = 0; i < 3; i++)for(int j = 0; j < 3; j++){if(min_num > array[i][j])min_num = array[i][j];}}void num_calc(int array[3][3],double & aver_num,int & max_num,int & min_num){aver_calc(array,aver_num);max_calc(array,max_num);min_calc(array,min_num);}
全部回答
- 1楼网友:玩家
- 2021-02-13 05:57
对的,就是这个意思
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯