函式_找出中位數

 avatar
user_3763047219
c_cpp
2 years ago
489 B
0
Indexable
Never
void mid(int a[5], int n);


#include <stdio.h>
void mid(int a[5], int n) {
    for (int i = 4; i > 0; i--) {
        for (int j = 0; j < i; j++) {
            if (a[j] > a[j + 1]) {
                int temp = a[j];
                a[j] = a[j + 1];
                a[j + 1] = temp;
            }
        }
    }
    printf("Median = %d", a[2]);
}


int main() {
    int a[5], i;
    for (i = 0; i < 5; i++)
        scanf("%d", &a[i]);
    mid(a, 5);
    return 0;
}