fork(2) download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. int n;
  5. int *list;
  6. int * MergeSort(int *A, int x, int y);
  7.  
  8.  
  9. void main()
  10. {
  11. printf("Enter the no. of integers in the array: ");
  12. scanf("%d",&n);
  13.  
  14. list=(int *)malloc(n*sizeof(int));
  15.  
  16. for(int i=0;i<n;i++)
  17. {
  18. printf("\nEnter a no.: ");
  19. scanf("%d",&list[i]);
  20. }
  21.  
  22. MergeSort(list,0,n-1);
  23.  
  24. for(int i=0;i<n;i++)
  25. {
  26. printf("%d ",list[i]);
  27. }
  28.  
  29. }
  30.  
  31. int * MergeSort(int *A, int x, int y)
  32. {
  33. if(x==y)
  34. {
  35. return A;
  36. }
  37.  
  38. else
  39. {
  40. int size=1+y-x;
  41. int half=size/2;
  42.  
  43. MergeSort(A, 0, half-1);
  44. MergeSort(A, half, y);
  45.  
  46.  
  47. int *C;
  48. C=(int *)malloc(size*sizeof(int));
  49. int j=0;
  50. int k=half;
  51. int i=0;
  52.  
  53.  
  54. while((j<half)||(k<size))
  55. {
  56. if(A[j]<=A[k])
  57. {
  58. C[i]=A[j];
  59. j++;
  60. }
  61. else
  62. {
  63. C[i]=A[k];
  64. k++;
  65. }
  66. i++;
  67. }
  68.  
  69.  
  70. if(j==half)
  71. {
  72. while(i<size)
  73. {
  74. C[i]=A[k];
  75. i++;
  76. k++;
  77. }
  78. }
  79. else if(k==size)
  80. {
  81. while(i<size)
  82. {
  83. C[i]=A[j];
  84. i++;
  85. j++;
  86. }
  87. }
  88.  
  89.  
  90.  
  91. return C;
  92. }
  93.  
  94. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:9:6: warning: return type of ‘main’ is not ‘int’ [-Wmain]
 void main()
      ^
prog.c: In function ‘main’:
prog.c:16:2: error: ‘for’ loop initial declarations are only allowed in C99 mode
  for(int i=0;i<n;i++)
  ^
prog.c:16:2: note: use option -std=c99 or -std=gnu99 to compile your code
prog.c:24:10: error: redefinition of ‘i’
  for(int i=0;i<n;i++)
          ^
prog.c:16:10: note: previous definition of ‘i’ was here
  for(int i=0;i<n;i++)
          ^
prog.c:24:2: error: ‘for’ loop initial declarations are only allowed in C99 mode
  for(int i=0;i<n;i++)
  ^
stdout
Standard output is empty