题解 | #最高分与最低分之差#
最高分与最低分之差
https://www.nowcoder.com/practice/e0e4f81dcd55408a8973f8033bbeb1d2
#include <stdio.h>
int main() {
unsigned int n = 0;
unsigned char inputScore = 0;
/* 因为成绩的范围为0 ~ 100,那么我们假定最高分为0,最低分为100 */
unsigned char maxScore = 0, minScore = 100;
scanf("%u", &n);
/* 输入n个成绩(整数表示,范围0~100),以空格隔开并求出其中最高分数和最低分数 */
for (unsigned int i = 0; i < n; i++) {
/* %hhu 表示按十进制整数读取一个 unsigned char 值 */
scanf("%hhu", &inputScore);
if (maxScore < inputScore)//更新最高分
maxScore = inputScore;
if (minScore > inputScore)//更新最低分
minScore = inputScore;
}
/* 输出n个成绩中最高分数和最低分数的差 */
printf("%hhu\n", maxScore - minScore);
return 0;
}
