输出若干个学生成绩中的最高分,要求用指针函数实现
时间: 2024-06-14 15:04:49 浏览: 39
以下是使用指针函数实现输出若干个学生成绩中的最高分的代码示例:
```c
#include <stdio.h>
float* search(float(*p)[4], int n) {
float* pt;
pt = *(p + n);
return (pt);
}
float findMaxScore(float(*p)[4], int n) {
float maxScore = 0;
for (int i = 0; i < n; i++) {
float* pt = search(p, i);
for (int j = 0; j < 4; j++) {
if (*(pt + j) > maxScore) {
maxScore = *(pt + j);
}
}
}
return maxScore;
}
int main(void) {
float score[][4] = {
{85, 65, 75, 99},
{75, 32, 64, 85},
{51, 77, 66, 93},
{78, 95, 88, 91}
};
int numStudents = sizeof(score) / sizeof(score[0]);
float maxScore = findMaxScore(score, numStudents);
printf("最高分为: %.1f\n", maxScore);
return 0;
}
```
输出结果:
```
最高分为: 99.0
```
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-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)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![application/x-zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)