I have written a program in C for the Merge Sort but I get a Segmentation Fault and I don't know why? Could you give me a hint what could be wrong?

That's the code:

```
#include <stdio.h>
#include <math.h>

  void Merge(int A[],int p,int q,int r){
       int n1,n2,i,j,k;
       n1=q-p+1;
       n2=r-q;
       int L[n1],R[n2];
       for (i=0; i<n1; i++) L[i]=A[p+i-1];
       for (j=0; j<n2; j++) R[j]=A[q+j];
       i=0;
       j=0;
       for (k=p; k<r; k++){
          if (L[i]<=R[j]){
              A[k]=L[i];
              i=i+1;
          }
          else{
          A[k]=R[j];
          j=j+1;
          }
          }
  }

  void Sort(int A[],int p,int r){
      int q;
       if (p<r){
          q=floor((p+r)/2);
          Sort(A,p,q);
          Sort(A,q+1,r);
          Merge(A,p,q,r);
        }
        }  
 int main()
 {
    int n,i,p,r;
    printf("Give a value for n: \n");
    scanf("%d",&n);
    int A[n];
    for (i=0; i<n; i++){
        printf ("Give %d th value of the array: \n",i+1 );
        scanf("%d",&A[i]);
    }
    printf("Give me a value for p:\n");
    scanf("%d",&p);
    printf("Give me a value for r:\n");
    scanf("%d",&r);
    Sort(A,p,r);
    printf("p=%d, r=%d \n \n", p,r);
    for (i=0; i<n; i++) printf("%d", A[i]);
    return 0;
 }

```

That's what I got,giving inputs at the terminal:

```

Give a value for n:
8
Give 1 th value of the array:
1
Give 2 th value of the array:
6
Give 3 th value of the array:
5
Give 4 th value of the array:
3
Give 5 th value of the array:
5
Give 6 th value of the array:
4
Give 7 th value of the array:
2
Give 8 th value of the array:
7
Give me a value for p:
2
Give me a value for r:
6
Segmentation fault (core dumped)

```

Have I done maybe something wrong at the function Sort?