Two different way to obtain the maximum and minimum
Code 1:
#include <stdio.h> int main() { float score[5], sum = 0, max, min; int i; printf("请输入5名童鞋的成绩:\n"); for (i = 0; i < 5; i = i + 1) scanf_s("%f", &score[i]); max = min = score[0]; for (i = 0; i < 5; i = i + 1) { if (max <=Score [I]) max = Score [I]; IF (min> = Score [I]) min = Score [I]; } the printf ( " maximum score:. 1F% \ n- " , max); the printf ( " lowest score:% 1F \ n-. " , min); }
Code 2:
#include <stdio.h> int main() { float score[5], sum = 0 ; int i,max, min; printf("请输入5名童鞋的成绩:\n"); for (i = 0; i < 5; i = i + 1) scanf_s("%f", &score[i]); max = min = 0; for (i = 0; i < 5; i = i + 1) { if (max <=Score [I]) max = I; IF (min> = Score [I]) min = I; } the printf ( " subscripts:.% d score is the highest score:% 1F \ n- " , max, Score [ max]); the printf ( " subscripts: results of% d lowest score:% 1F \ n-. " , min, score [min]); }