pointer Find Minimum Number

PHOTO EMBED

Sun Jun 09 2024 11:32:00 GMT+0000 (Coordinated Universal Time)

Saved by @meanaspotato #c #pointer

#include <stdio.h>

int find_min_index(int* numbers, int length);

int main(void)
{
    int array1[] = { 1, 3, 5, 7, 9, 11 };
    int array2[] = { 2, -4, 6, -8, 10, -12, 14, -16, 4 };
    int array3[] = { 6, 4, 1, 4, 5, 3, 2 };
 
    printf("Min's index in array1 is: %d\n", find_min_index(array1, 6));
    printf("Min's index in array2 is: %d\n", find_min_index(array2, 9));
    printf("Min's index in array3 is: %d\n", find_min_index(array3, 7));
 
    return 0;
}

int find_min_index(int* numbers, int length)
{
    // TODO: Insert your code here!
    
    int min_index = 0;
    
    for(int i = 0; i < length; i++)
    {
        if( numbers[i] < numbers[min_index] )
        {
            min_index = i;
        }
    }
    return min_index;
}
content_copyCOPY

Expected Min's index in array1 is: 0 Min's index in array2 is: 7 Min's index in array3 is: 2 This exercise aims to introduce students to array manipulations in C, with a focus on finding the index of the minimum value in an array. Students will implement a function called find_min_index that accepts an integer array and its length as parameters and returns the index of the smallest value in the array. Requirements Function Declaration and Definition Declare and define a function called find_min_index that: Takes an integer pointer numbers and an integer length as parameters. Searches for the minimum value in the array and returns the index of that value. Example function signature: int find_min_index(int* numbers, int length); Main Function In the main() function: Declare and initialize three arrays named array1, array2, and array3 with given values. Call find_min_index on each array and print the returned index using printf.