Solution
Follow the following steps to achieve this task
- Read the entered array size and store that value into the variable LENGTH.
- Read the entered elements using scanf and store the entered array elements into the array using for loop for(i=0;i<LENGTH;i++).
Initialise min, max values with the 1st element of the array.
- Compare min, max values with a[i],
- If min value is greater than a[i] then initialise min=a[i] and if max value is less than a[i] then initialise max=a[i]. Repeat this step for each element of the string using for loop which is having the structure for(i=1;i<LENGTH
- ;i++).
- Print the minimum of the array and maximum of the array values.
// Online C compiler to run C program online
#include <stdio.h>
#define LENGTH 8
int main() {
int a[LENGTH],i,min,max;
printf("Array size was set to 8\n");
for(i=0; i< LENGTH; i++){
printf("Enter elements in index array[%d] ", i);
scanf("%d",&a[i]);
}
min=max=a[0];
for(i=1; i< LENGTH; i++)
{
if(min>a[i])
min=a[i];
if(max<a[i])
max=a[i];
}
printf("The minimum value in the array is : %d",min);
printf("\n The maximum value in the array is : %d",max);
return 0;
}
Tags:
C