Write a function that returns a pointers to the maximum value of. An array of doubles if array is empty return null double maximum (double *a,int size)
Answers
Answer:
the following into the new one is the best
Answer:
/* Write a function that returns a pointer to the maximum value of an array of
double's. If the array is empty, return NULL. */
#include<stdio.h>
double *fun(double *,int);
int main()
{
int n, i;
printf("\nEnter the size of array: ");
scanf("%d",&n);
double arr[n];
printf("Enter the elements of the array: ");
for ( i = 0; i < n; i++)
{
scanf("%lf",&arr[i]);
}
double *ptr;
ptr = arr;
printf("Address of ptr = %u\n",ptr);
ptr = fun(arr, n);
printf("Address of pointer is = %u\n",ptr);
return 0;
}
double *fun(double *arr,int n)
{
if(n == 0)
{
return NULL;
}
int i;
double *max;
double *p;
max = arr;
p = arr;
for ( i = 0; i < n; i++)
{
if (*p > *max)
max = p;
p++;
}
printf("Largest number in the array is: %lf\n",*max);
return(max);
}
Explanation: