指標_陣列的最大值

 avatar
user_3763047219
c_cpp
2 years ago
505 B
0
Indexable
Never
int max(int* iptr, int n);


int max(int* iptr, int n) {
    int max = 0;
    for (int i = 0; i < n; i++) {
        iptr--;
        if (max < *iptr) {
            max = *iptr;
        }
    }
    return max;
}

#include <stdio.h>

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;
}