Can anyone help me spot the error in my program in finding the minimum and maximum element in a agiven array. I know that it is a simple error but I cannot figure it out.
#include <stdio.h>
# define SIZE 10
int main()
{
int min;
int max;
int i; //counter variable
int arr[SIZE] = {2,4,5,7,8,100,4,1};
//check min and max of given array
min = arr[0];
max = arr[0];
for(i =0; i< SIZE;i++)
{
if(arr[i]<min)
{
min = arr[i];
}
if(arr[i]>max)
{
max = arr[i];
}
}
printf("minimum is %d\n",min);
printf("maximum is %d\n",max);
return 0;
}
SIZE.0forminSIZEis10, the array is initialized with8elements only. The rest are zeros