如下是VS2022的C语言代码
#include<stdio.h>
#include<math.h>
#define N 10
int main(void)
{
int I, alx, alxEnd, blx, blxEnd, clx, glx, size;
_Bool CopyA, CopyB;
int arr[N];
int temp[N] = { 0 };
printf("Define a random number group:\n");
for (I = 0; I < N; ++I) /*给数组赋值随机变量*/
{
arr[I] = (int)(rand() % 100);
printf("%d ", arr[I]);
}
printf("\n");
for (size = 1; size < N; size += size); //归并排序
{
for (glx = 0; glx < N; glx += 2 * size)
{
alx = glx;
alxEnd = (N < (alx + size)) ? N : (alx + size);
blx = glx + size;
blxEnd = (N < (blx + size)) ? N : (blx + size);
clx = glx;
while ((alx < alxEnd) || (blx < blxEnd))
{
CopyA = 0;
CopyB = 0;
if ((alx < alxEnd) && (blx < blxEnd))
{
CopyA = (arr[alx] < arr[blx]);
CopyB = !CopyA;
}
else
{
if (alx >= alxEnd)
{
CopyB = 1;
}
else
{
CopyA = 1;
}
}
if (CopyA == 1)
{
temp[clx] = arr[alx];
alx++;
}
if (CopyB == 1)
{
temp[clx] = arr[blx];
blx++;
}
clx++;
}
}
for (I = 0; I < N; ++I)
{
arr[I] = temp[I];
}
}
printf("Here is the group that has been arranged:\n");
for (I = 0; I < N; ++I)
{
printf("%d ", arr[I]);
}
return 0;
}
我用X-program就成功了
这是为什么呀?