Language: C


int main(void){
  int n,i;
  int A[N];

  scanf("%d",&n);
  for(i=0; i<n; i++) scanf("%d",&A[i]);
  Merge_Sort(A, 0, n);

  for(i=0; i<n; i++){
    if(i != 0) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n%d\n",count);

  return 0;
}

void Merge(int *A,int left,int mid,int right){
  int n1,n2,i,j,k;
  int L[N],R[N];

  n1 = mid -left;
  n2 = right - mid;

  for(i=0; i<n1; i++) L[i] = A[left + i];
  for(i=0; i<n2; i++) R[i] = A[mid + i];

  L[n1] = 1000000000;
  R[n2] = 1000000000;
  i = j = 0;

  for(k=left; k<right; k++){
    if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
    }else{
      A[k] = R[j];
      j++;
    }
    count++;
  }
}

void Merge_Sort(int *A,int left,int right){
  int mid;

  if(left+1 < right){
    mid = (left + right)/2;
    Merge_Sort(A, left, mid);
    Merge_Sort(A, mid, right);
    Merge(A, left, mid, right);
  }

}

Compiler output:
main.c: In function 'main':
main.c:4:9: error: 'N' undeclared (first use in this function)
    4 |   int A[N];
      |         ^
main.c:4:9: note: each undeclared identifier is reported only once for each function it appears in
main.c:6:3: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
    6 |   scanf("%d",&n);
      |   ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
  +++ |+#include <stdio.h>
    1 | 
main.c:6:3: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
    6 |   scanf("%d",&n);
      |   ^~~~~
main.c:6:3: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:8:3: error: implicit declaration of function 'Merge_Sort' [-Wimplicit-function-declaration]
    8 |   Merge_Sort(A, 0, n);
      |   ^~~~~~~~~~
main.c:11:16: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
   11 |     if(i != 0) printf(" ");
      |                ^~~~~~
main.c:11:16: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:11:16: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:11:16: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:12:5: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
   12 |     printf("%d",A[i]);
      |     ^~~~~~
main.c:12:5: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:14:3: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
   14 |   printf("\n%d\n",count);
      |   ^~~~~~
main.c:14:3: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:14:19: error: 'count' undeclared (first use in this function)
   14 |   printf("\n%d\n",count);
      |                   ^~~~~
main.c: In function 'Merge':
main.c:21:9: error: 'N' undeclared (first use in this function)
   21 |   int L[N],R[N];
      |         ^
main.c:41:5: error: 'count' undeclared (first use in this function)
   41 |     count++;
      |     ^~~~~
main.c: At top level:
main.c:45:6: warning: conflicting types for 'Merge_Sort'; have 'void(int *, int,  int)'
   45 | void Merge_Sort(int *A,int left,int right){
      |      ^~~~~~~~~~
main.c:8:3: note: previous implicit declaration of 'Merge_Sort' with type 'void(int *, int,  int)'
    8 |   Merge_Sort(A, 0, n);
      |   ^~~~~~~~~~