函数题:全局变量和静态变量
下面代码中,main函数三次调用函数fun,每次输入一组正整数,最后输出全部数据的最大值,最小值,总和,平均值。
定义函数fun,完成一组数据处理,每组数组个数不确定,以负数结束输入,空格分隔。
### 函数接口定义:
c++
int fun (void);
fun返回值为这组数据的个数。(不包括结束标志)
### 裁判测试程序样例:
c++
在这里给出函数被调用进行测试的例子。例如:
#include <stdio.h>
int max=0,min=0,total=0;
int fun (void);
int main()
{
int n;
n=fun();
n=fun();
n=fun();
printf("max=%d min=%d total=%d ave=%.1f",max,min,total,(float)total/n);
}
/* 请在这里填写答案 */
### 输入样例:
in
10 20 30 50 -1
11 21 31 41 51 -1
55 56 60 -1
### 输出样例:
out
max=60 min=10 total=436 ave=36.3
答案:若无答案欢迎评论
定义函数fun,完成一组数据处理,每组数组个数不确定,以负数结束输入,空格分隔。
### 函数接口定义:
c++
int fun (void);
fun返回值为这组数据的个数。(不包括结束标志)
### 裁判测试程序样例:
c++
在这里给出函数被调用进行测试的例子。例如:
#include <stdio.h>
int max=0,min=0,total=0;
int fun (void);
int main()
{
int n;
n=fun();
n=fun();
n=fun();
printf("max=%d min=%d total=%d ave=%.1f",max,min,total,(float)total/n);
}
/* 请在这里填写答案 */
### 输入样例:
in
10 20 30 50 -1
11 21 31 41 51 -1
55 56 60 -1
### 输出样例:
out
max=60 min=10 total=436 ave=36.3
答案:若无答案欢迎评论