Write a program to compute the maximum value of the function
f(x,y)=4x−6y
given multiple pairs of integers (x,y).
The computation should be implemented in a function eval_f(iptr, n, index).
The first parameter iptr is a list of pointers, each pointing to a pair of integers (x, y).
The second parameter n represents the number of pairs.
The third parameter index is used to store the position of the pair (x,y) that produces the maximum value of f(x, y).
For example, if iptr[3] produces the maximum value of the function, then the integer pointed to by index should be set to 3.
If multiple pairs produce the same maximum value, index should store the largest index among them.
The program reads several pairs of integers (x, y) until end-of-file (EOF), and prints two integers:
the maximum value and the index (0-based 從零開始) of the pair that produced it.
function to be completed:
int eval_f(int *iptr[], int n, int *index);
main program:
#include <stdio.h>
#define N 256
int eval_f(int *iptr[N], int n, int *index);
int main(void)
{
int n = 0;
int x, y;
int xy[2 * N];
int xy_n = 0;
int max, max_index;
int *iptr[N];
while (scanf("%d%d", &x, &y) != EOF) {
iptr[n] = &(xy[xy_n]);
n++;
xy[xy_n] = x;
xy_n++;
xy[xy_n] = y;
xy_n++;
}
max = eval_f(iptr, n, &max_index);
printf("%d %d\n", max, max_index);
return 0;
}
int eval_f(int *iptr[N], int n, int *index)
{
// Your Task
}
A sequence of integer pairs (x, y) representing the parameters of the function f(x,y)=4x−6y.
The number of pairs n satisfies 0<n≤256.
You should add the EOF (End of File) character at the end of your input in the terminal.
To do this, first press Enter, then press Ctrl + Z, and finally press Enter again.
Two integers:
The maximum value of f(x,y).
The index of the pair that produced this maximum value.
If multiple pairs give the same maximum value, output the largest index among them.
Ensure that the output, including formatting 輸出格式, exactly matches the provided samples.