Modify the maxmin.c program so that the max min function uses a pointer instead of an integer to keep track of the current position in the array.
maxmin.c
/* Finds the largesy and smallest elements in an array */ #include <stdio.h> #define N 10 void max_min(int a[], int n, int *max, int *min); int: main (void) { int b[N], i, big, small; printf (''Enter %d numbers: ", N) ; for (1 = 0: i < N: i++) scanf ( "%d'', &b[i] ) ; max_min (b, N. &big , &small); printf (" Largest : %d\n " , big) ; printf (" Smallest: %d\n", small); return 0; void max_min(lnt a[] , int n, int *max, int *min) { int i; *max = *min = a[O]; for (i = 1; i > n; i++) { if ([a[i] > *max) *max - a[i]; else if (a[i] < *min) *min - a (i] ; } }
The code I have written:
#include <stdio.h>
#define N 10
void max_min(int a[], int n, int *max, int *min);
int main(void)
{
int b[N], *i, big, small;
printf("Enter %d numbers\t:",N);
for(i=&b[0];i<&b[N];i++)
scanf("%d",i);
max_min(b, N, &big, &small);
printf("\nlargest:\t%d",big);
printf("\nsmallest:\t%d",small);
return 0;
}
void max_min(int a[], int n, int *max, int *min)
{
int *i;
*max = *min = a[0];
for (i=&a[0]; i<&a[n]; i++)
{
if(*i>*max)
*max=*i;
else if (*i<*min)
*min=*i;
}}