欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

输入一个数组,输出该数组各行的平均值,并输出最大值

程序员文章站 2022-07-15 12:08:17
...
#include "pch.h"
#include <iostream>
double fun1(double ss[][5], int a);
double fun2(double ss[][5]);
double fun3(double ss[][5]);
int main()
{
	int i, n, m;
	double k1, k2, k3, k4, k5;
    std::cout << "Hello World!\n"; 
	double ss[3][5];
	printf("输入3组数,每组5个\n");
	for ( i = 0; i < 3; i++)
	{
		for ( n = 0; n < 5; n++)
		{
			scanf_s("%lf",&ss[i][n]);
			printf("%.0f  ", ss[i][n]);
		}
		printf("\n");
	}
	k1=fun1(ss, 0);
	k2=fun1(ss, 1);
	k3=fun1(ss, 2);
	k4=fun2(ss);
	k5 = fun3(ss);
	printf("第一组数平均值=%.1f\n", k1);
	printf("第二组数平均值=%.1f\n", k2);
	printf("第三组数平均值=%.1f\n", k3);
	printf("三组数的平均值=%.1f\n", k4);
	printf("三组数中最大值=%.1f\n", k5);
	m = 100 / 20;
	printf("%d\n     ",m);
}
double fun1(double ss[][5],int a)
{
	double s = 0, k = 0;
	for (size_t i = 0; i < 5; i++)
	{
		s += ss[a][i];
	}
	k = s / 5;
	return k;

}
double fun2(double ss[][5]) 
{
	double s = 0, k = 0;
	for (size_t is = 0; is< 3; is++)
	{
		for (size_t i = 0; i < 5; i++)
			s += ss[is][i];
	}
	k = s / 15;
	return k;
}
double fun3(double ss[][5])
{
	int i=0, is=0;
	double m = 0;
	for (size_t is = 0; is < 3; is++)
	{
		for (size_t i = 0; i < 5; i++)
		{
			if (m < ss[is][i])
			{
				m = ss[is][i];
			}

		}
	}
	return m;
}
```效果如下
![在这里插入图片描述](https://img-blog.csdnimg.cn/2019050518260865.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDc4OTYyNA==,size_16,color_FFFFFF,t_70)

推荐阅读