Complete the program below: [1] The main function should first prompt the user f
ID: 3737692 • Letter: C
Question
Complete the program below: [1] The main function should first prompt the user for the elements of an array with N integer entries and then read in those values. [2] The main function should then call the function max_min. [3] The function max_min should compute the maximum and minimum values in the array (using pointers) and pass those values back to main() using pointer parameters. [4] Finally, in main() print out the maximum and minimum values of the array.
Be sure to use the same variables as declared in the incomplete program below.
You must use pointers to code this program.
#include <stdio.h>
#define N 10
void max_min (int a[], int n, int *max, int *min)
{
int i;
…
}
main()
{
int b[N], i, big, small;
…
}
Explanation / Answer
#include <stdio.h>
#define N 10
void max_min (int a[], int n, int *max, int *min)
{
int i;
*min = a[0];
*max=a[0];
for(i=0;i<n;i++) {
if(*max<a[i]) {
*max = a[i];
}
if(*min>a[i]) {
*min = a[i];
}
}
}
main()
{
int b[N], i, big, small;
printf("Enter %d integers: ",N);
for(i=0;i<N;i++) {
scanf("%d", &b[i]);
}
max_min(b, N, &big, &small);
printf("Max: %d ", big);
printf("Min: %d ", small);
}
Output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.