138. 指標陣列的最大值

 avatar
user_6817964
c_cpp
a year ago
507 B
0
Indexable
Never
int max(int* iptr, int n);
int max(int* iptr, int n) {
    int max = 0;
    iptr = iptr - (n - 1);
    for (int i = 0; i < n; i++) {
        if (*iptr > max) {
            max = *iptr;
        }
        iptr++;
    }
    return max;
}

int main() {
    int n, i;
    int array[100];
    int* iptr;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &(array[i]));
        iptr = &(array[i]);
        iptr++;
    }
    printf("%d\n", max(iptr, n));
    return 0;
}