C Program to Find Maximum and Minimum from Array

C Program to Find Maximum and Minimum from Array

Write C Program to Find Maximum and Minimum from Array

// C Program to Find Maximum and Minimum from Array

#include <stdio.h>

int main()
{
	int A[10] = {10, 98, 2, 3, 41, 5, 6, 17, 0, 94}, i;
	int min, max;

	printf("Array Elements :--> ");
	for(i=0; i<10; i++)
    {
        printf("%d  ", A[i]);
    }

	min = max = A[0];
	int n = sizeof(A)/sizeof(A[0]);

	for(i = 0;i < n; i++)
	{
		if(A[i] < min)
		{
			min = A[i];
		}
		if(A[i] > max)
		{
			max = A[i];
		}
	}


	printf("\n\nThe minimum element is :--> %d", min);
	printf("\nThe maximum element is :--> %d", max);
	return 0;
}

Output:

Array Elements :--> 10  98  2  3  41  5  6  17  0  94

The minimum element is :--> 0
The maximum element is :--> 98