1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include <stdio.h> #define N_DATA 8 int data[N_DATA] = { 12, 23, 98, 45, 11, 92, 56, 79 }; int find_min(int data[], int start, int n) { int i, least; least = start; for (i = start + 1; i < n; i++) { if (data[i] < data[least]) least = i; } return least; } int main(void) { int min_idx; min_idx = find_min(data, 0, N_DATA); printf("°¡Àå ÀÛÀº °ªÀº %d ÀÔ´Ï´Ù.\n", data[min_idx]); } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include <stdio.h> #define N_DATA 8 int data[N_DATA] = { 12, 23, 98, 45, 11, 92, 56, 79 }; int find_max(int data[], int start, int n) { int i, max_id; max_id = start; for (i = start + 1; i < n; i++) { if (data[i] > data[max_id]) max_id = i; } return max_id; } int main(void) { int max_idx; max_idx = find_max(data, 0, N_DATA); printf("°¡Àå Å« °ªÀº %d ÀÔ´Ï´Ù.\n", data[max_idx]); } | cs |