Max no. in 2 arrays

PHOTO EMBED

Sun Aug 25 2024 13:02:12 GMT+0000 (Coordinated Universal Time)

Saved by @Xyfer

#include <stdio.h>

int main() {
    int n, m;
    
    // Input number of math scores and the scores themselves
    scanf("%d", &n);
    int mathScores[n];
    for (int i = 0; i < n; ++i) {
        scanf("%d", &mathScores[i]);
    }
    
    // Input number of science scores and the scores themselves
    scanf("%d", &m);
    int scienceScores[m];
    for (int i = 0; i < m; ++i) {
        scanf("%d", &scienceScores[i]);
    }
    
    // Find the maximum score in both arrays
    int maxScore = mathScores[0];
    
    for (int i = 0; i < n; ++i) {
        if (mathScores[i] > maxScore) {
            maxScore = mathScores[i];
        }
    }
    
    for (int i = 0; i < m; ++i) {
        if (scienceScores[i] > maxScore) {
            maxScore = scienceScores[i];
        }
    }
    
    // Output the maximum score found
    printf("%d\n", maxScore);

    return 0;
}
content_copyCOPY