This is a simple program, that finds teh smallest and largest element of a 10-array. I'm not sure why I'm getting the segmentation fault(core dumped) error.
#include <stdio.h>
int main(void) {
int i, j, min, array[10], max, n;
//This loop get user input for the elements of the array
for(i = 0; i < 10; i++) {
printf("Enter element number %d:", i);
scanf("%d", &n);
array[i] = n;
}
min = array[0];
max = array[0];
//This loop finds the smallest element of the array
for(j = 0; j < 10; j++) {
if(min > array[j]) {
min = array[j];
}
}
//This loop finds the largest element of the array
for(j = 9; j >= 0; j++) {
if(max < array[j]) {
max = array[j];
}
}
printf("smallest value is: %d", min);
printf("largest value is: %d", max);
return 0;
}