编辑代码

#include <stdio.h>

void FindWorstScoreAndId(const int scores[],
                         int* ptr_worst_score,
                         int* ptr_worst_id);

void main(void){
    int scores[6] = {99, 88, 66, 92, 100, 59};
    
    int worst_score, worst_id;
    int* ptr_worst_score = &worst_score;
    int* ptr_worst_id = &worst_id;
     
    FindWorstScoreAndId(scores, ptr_worst_score, ptr_worst_id);
    printf("Worst score is %d.\n", *ptr_worst_score);
    printf("worst id is %d.\n", *ptr_worst_id);
    return;
}

void FindWorstScoreAndId(const int scores[],
                         int* ptr_worst_score,
                         int* ptr_worst_id){
    int cur_worst_score = scores[0];
    int cur_worst_id = 0;
    for (int i = 1; i < 6; ++i){
        if (scores[i] < cur_worst_score) {
            cur_worst_score = scores[i];
            cur_worst_id = i;
        }
    *ptr_worst_score = cur_worst_score;
    *ptr_worst_id = cur_worst_id + 1;
        
    }
}