编辑代码

#include <stdio.h>

int findMax(int arr[], int n) {
    if (n == 0) {
        return -1;  // 如果数组为空,返回一个特殊值(例如-1),或者根据需要进行错误处理
    }

    int max = arr[0];

    for (int i = 1; i < n; i++) {
        if (arr[i] > max) {
            max = arr[i];
        }
    }

    return max;
}

int main() {
    // 第一个测试用例
    int sequence1[] = {30, 19, 11, 25, 17, 2};
    int max1 = findMax(sequence1, 6);
    printf("最大值为: %d\n", max1);

    // 第二个测试用例
    int sequence2[] = {15, 7, 26, 10, 28, 42};
    int max2 = findMax(sequence2, 6);
    printf("最大值为: %d\n", max2);

    // 第三个测试用例
    int sequence3[] = {10, 20, 50, 3, 66, 10};
    int max3 = findMax(sequence3, 6);
    printf("最大值为: %d\n", max3);

    return 0;
}