Hey everyone, I was wondering if someone could take a look at my program and see if they can figure out why i'm getting this error during runtime. I believe the error is thrown because i'm accessing an illegal memory location (ie. doesn't exist), but I can't seem to find where. If anyone has any suggestions, they would be greatly appreciated.
Code:
#include<stdio.h>
void read (int[20]);
void print (int[20]);
int main(void){
int numbers[20];
read(numbers);
print(numbers);
return 0;
}
void read (int numbers[20]){ //Reads input and saves to an array
int num, j;
printf("Please enter 20 numbers between 10 and 100.\n");
for (j =0; j<20; j++){
scanf("%d", num);
numbers[j] = num;
}
}
void print (int numbers[20]){ //Prints the numbers of the array as long as they aren't
int j, n, flag =0; //of previous numbers.
for(j =0; j<20; j++){
if(j>0){
for(n =j; n>0; n--){
if(numbers[j]==numbers[n])
flag=1;
}
}
if (flag==0)
printf("%d, ", numbers[j]);
flag = 0;
}
}