14761 - Minimum Value in a Pointer Array   

Description

(20 points)

A pointer array is simply an array whose elements are pointers.

For example, if we declare:

int *iptr[10];

then iptr is an array containing ten integer pointers. Each element of iptr points to an integer stored in another array.

Your task is to write a function min that returns the minimum integer among the elements pointed to by a pointer array.

The function definition is:

int min(int *iptr[N], int n);

Example Usage

The following program shows how the min function can be used in the main function:

#include <stdio.h>
#define N 10
int min(int *iptr[N], int n);

int main (void)
{
    int i;
    int array[N];
    int *iptr[N];

    for (i = 0; i < N; i++) {
        scanf("%d", &(array[i]));
        iptr[i] = &(array[i]);
    }

    printf("%d\n", min(iptr, N));
    return 0;
}

int min(int *iptr[N], int n)
{
    // Your Task
}

Please implement the function min and complete the program in example usage.

Input

  • he input consists of N integers (where N = 10 in this problem).

  • These integers are read from standard input, separated by spaces or newlines.

Output

The program outputs the minimum value among the integers pointed to by the pointer array.

Ensure that the output, including formatting 輸出格式, exactly matches the provided samples.

Sample Input  Download

Sample Output  Download

Tags




Discuss