Segmentation fault when using a 1D array

Solution 1:

When the x and y arrays are created, n is uninitialized. There's no knowing how large these arrays will be. You loops are almost certainly accessing the array out of bounds.

You want to read n, then create the arrays. Of course you also want to error check the result of scanf.

    int n; // n is use to decide the size of array 

    printf("enter the size of array:");
    scanf("%d", &n);

    int x[n];
    int y[n];