C Programming code for Max & Min of an Array – KLE Tech

Here you go with the modular C programming code for the Min &Max of a 1D Array. Go through this C program to find the Min and Max of array elements using function.

CODE:

#include<stdio.h>

void readArray(int[],int);
void displayArray(int[],int);
void minmaxArray(int[],int);

int main()
{
int n,s ;
int arr[100];
printf("Enter the size of Array: ");
scanf("%d",&n);
printf("Enter the elements of array: \n");
readArray(arr,n);
minmaxArray(arr,n);
}

void readArray(int arr[],int n)
{
int i;
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
}

void displayArray(int arr[],int n)
{
int i;
for(i=0;i<n;i++)
{
printf("%d ",arr[i]);
}
}

void minmaxArray(int arr[],int n)
{
int min, max,i;
min=max=arr[0];
for(i=1; i<n; i++)
{
if(min>arr[i])
min=arr[i];
if(max<arr[i])
max=arr[i];
}
printf("minimum of array is : %d",min);
printf("\nmaximum of array is : %d",max);
}

OUTPUT

Enter the size of Array: 5
Enter the elements of array:
2
6
5
3
4
minimum of array is : 2
maximum of array is : 6
Process returned 0 (0x0) execution time : 6.803 s
Press any key to continue.

 

Please find some more codes of 1D Arrays, 2D Arrays, Pointers on the below page:

Top 100+ C Programming codes – KLE Technological University

 

Leave a Comment