Untitled
unknown
plain_text
10 months ago
1.1 kB
3
Indexable
#include <stdio.h>
#define SIZE 15
void find_min_max(int numbers[], int size) {
int min = numbers[0], max = numbers[0];
int min_index = 0, max_index = 0;
// Iterate through the array to find the min and max values and their indices
for (int i = 1; i < size; i++) {
if (numbers[i] < min) {
min = numbers[i];
min_index = i;
}
if (numbers[i] > max) {
max = numbers[i];
max_index = i;
}
}
// Output the results
printf("The smallest number is %d. It is at index %d.\n", min, min_index);
printf("The largest number is %d. It is at index %d.\n", max, max_index);
}
int main() {
// Insert the numbers directly into the array
int numbers[SIZE] = {15, 1, 2, 3, 1, 5, 6, 7, 1, -9, 2, 4, 3, 17, 3};
int size = SIZE;
// Display the numbers and find min/max
printf("The numbers are: ");
for (int i = 0; i < size; i++) {
printf("%d ", numbers[i]);
}
printf("\n");
find_min_max(numbers, size);
return 0;
}
Editor is loading...
Leave a Comment