min max array c code example
Example 1: Write a program to find max and min element in an array. User must input 5 elements in the array.
#include <stdio.h>
#include <conio.h>
{
scanf("%d",&a[i]);
}int main()
{
int a[1000],i,n,min,max;
printf("Enter size of the array : ");
scanf("%d",&n);
printf("Enter elements in array : ");
for(i=0; i<n; i++)
min=max=a[0];
for(i=1; i<n; i++)
{
if(min>a[i])
min=a[i];
if(max<a[i])
max=a[i];
}
printf("minimum of array is : %d",min);
printf("\nmaximum of array is : %d",max);
return 0;
}
Example 2: Write a interactive C program to find the MINIMUM array elements in a given 3X3 matrix.
#include <stdio.h> #include <limits.h> int main() { int matrix[3][3]; printf("Enter the elements one-by-one:\n"); for(int row = 0; row < 3; row++) { for(int col = 0; col < 3; col++) { printf("%d %d: ", row+1, col+1); scanf("%d", &matrix[row][col]); printf("\n"); } } int min = INT_MAX; int max = INT_MIN; for(int i = 0; i < 3; i++){ for(int j = 0; j < 3; j++) { if(matrix[i][j] < min) min = matrix[i][j]; if(matrix[i][j] > max) max = matrix[i][j]; } } printf("Minimum value: %d\nMaximum Value: %d", min, max); return 0; }