scanfscore()函数用于输入学生的成绩
int scanfscore(int score[N])//输入学生的成绩
{int i = -1;do {i++;printf("输入学生成绩:");scanf("%d", &score[i]);} while (score[i] >= 0);return i;
}
findmax()用于寻找最大值
int findmax(int score[N], int n)
{int max =score[0];int i = 0;int maxIndex = 0;for (i = 1; i < n; i++){if (score[i] > max){max = score[i];maxIndex = i;} }return maxIndex;
}
完整代码
#include<stdio.h>
#define N 40
int scanfscore(int score[N])//输入学生的成绩
{int i = -1;do {i++;printf("输入学生成绩:");scanf("%d", &score[i]);} while (score[i] >= 0);return i;
}
int findmax(int score[N], int n)
{int max =score[0];int i = 0;int maxIndex = 0;for (i = 1; i < n; i++){if (score[i] > max){max = score[i];maxIndex = i;} }return maxIndex;
}
int main()
{int score[N];int n = 0;int maxi = 0;int i = 0;int temp = 0;n = scanfscore(score);printf("有%d个同学\n", n);maxi = findmax(score, n);printf("最大值的数组下标为%d\n", maxi);printf("最高分为%d",score[maxi]);return 0;
}