题解 | #最高分与最低分之差#
最高分与最低分之差
https://www.nowcoder.com/practice/e0e4f81dcd55408a8973f8033bbeb1d2
#include <stdio.h> int main() { int arr[10000]; int scoreNum = 0;//成绩个数 int maxScore = 0;//最高成绩 int minScore = 0;//最低成绩 scanf("%d", &scoreNum);//输入成绩个数 for(int i = 0; i < scoreNum; i++) {//逐个输入成绩 scanf("%d", &arr[i]); while(arr[i] > 100 || arr[i] < 0) { printf("成绩范围应为0~100,请重新输入成绩:"); scanf("%d", &arr[i]); } if(0 == i) { maxScore = arr[i]; minScore = arr[i]; } else { if(maxScore < arr[i]) { maxScore = arr[i]; } if(minScore > arr[i]) { minScore = arr[i]; } } } printf("%d", maxScore - minScore); return 0; }