用V语言编写程序,实现以下成绩处理功能: (1)输入10个成绩(整数类型,数组名记为a) ; (2)计算并输出最高分(记为Max)、最低分(记为Min)与成绩中值(记为Midd),其中成绩中 值为最高分与最低分的平均值(保留一位小数输出); (3)将Midd及以上的成绩归为A档,Midd以下的成绩归为B档,统计并输出A、B两档的人数。 要求最大值、最小值分别用函数max、min函数实现,其它功能在主函数中实现,max、min的结构如下: int max(int a[]) { //求数组a的最大值。 } int min(int a[]) { //求数组a的最小值。 } 运行示例:(要求输入输出按运行示例格式实现) 输入:88 59 50 74 60 99 75 90 68 70 输出:Max=99, Min=50, Midd=74.5, A=4, B=6
时间: 2024-01-22 14:19:32 浏览: 14
以下是V语言实现的程序代码:
```v
import std
fn main() {
mut a := [10]int{}
for i in 0..10 {
print('请输入第${i+1}个成绩:')
a[i] = std.in.readInt()
}
mut max := max(a)
mut min := min(a)
mut midd := (max + min) as f32 / 2
midd = round(midd * 10) / 10 // 保留一位小数
mut count_a := 0
mut count_b := 0
for score in a {
if score >= midd {
count_a++
} else {
count_b++
}
}
println('Max=$max, Min=$min, Midd=$midd, A=$count_a, B=$count_b')
}
fn max(a []int) int {
mut max := a[0]
for i in 1..a.len {
if a[i] > max {
max = a[i]
}
}
return max
}
fn min(a []int) int {
mut min := a[0]
for i in 1..a.len {
if a[i] < min {
min = a[i]
}
}
return min
}
```
运行示例:
```
请输入第1个成绩:88
请输入第2个成绩:59
请输入第3个成绩:50
请输入第4个成绩:74
请输入第5个成绩:60
请输入第6个成绩:99
请输入第7个成绩:75
请输入第8个成绩:90
请输入第9个成绩:68
请输入第10个成绩:70
Max=99, Min=50, Midd=74.5, A=4, B=6
```
相关推荐
![text/plain](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)