数组排序的代码,在运行时显示:Stack around the variable 'array' was corrupted.
以下为源代码:
#include<stdio.h>
main() {
//定义数组
int array[10];
int p;
int i,j;
int min;
for (i = 0;i < 10;i = i + 1) {
scanf_s("%d", &array[i]);
}
//取最小值
for (i = 0;i < 9;i = i + 1) {
min = array[i];//设置当前为最小值
p = i + 1;//元素位置
for (j = i + 1;j < 10;j = j + 1) {
if (array[j] < min) {
min = array[j];
p = j + 1;
}
}
array[j] = array[i];
array[i] = min;
}
//交换元素值
for (i = 0;i < 10;i =i + 1) {
printf("%d", array[i]);
printf(" ");
}