Search

# 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;

}

### Recent Posts

See All

#### Highest Divisor - CodeChef Solution | AskTheCode

CodeChef Feb Long Challenge Solution - Highest Divisor in C | Ask The Code...You are given an integer N. Find the largest integer...more

#### Enormous Input Test - CodeChef Solution in C | AskTheCode

CodeChef Practice Problem Solution in C Programming...Ask The Code...The purpose of this problem is to verify whether the method...Read more

#### C Program to find a number having max sum of divisors & also its position in the array

C Programming - AskTheCode | Write a C program display the number with maximum sum of divisors and its position in array...Ask The Code...