Max Min function in C

Random Post

#include <stdio.h>

int Max(float arr[],int n)

{

float maximum=-999999.99;

for (int i = 0; i < n; i++)

{

if (arr[i]>maximum)

{

maximum=arr[i];

}

}

return maximum;

}

int Min(float arr[], int n)

{

float minimum=999999.99;

for (int i = 0; i < n; i++)

{

if (arr[i]<minimum)

{

minimum=arr[i];

}

}

return minimum;

}

int main()

{

int n,i;

printf("Enter the number of elements: ");

scanf("%d",&n);

float arr[n];

for (int i = 0; i < n; i++)

{

printf("\nEnter the element[%d]: ",i+1 );

scanf("%f",&arr[i]);

}

float maxValue=Max(arr,n);

float minValue=Min(arr,n);

printf("\nThe maximum element in the array is: %.2f.",maxValue);

printf("\nAnd, the minimum element in the array is: %.2f.",minValue);

return 0;

}

10 views

Recent Posts

See All

"Believe you can and you're halfway there"