练习:已知一整型数组
a[6]={10,3,9,7,1,5},删除其中最小元素,其余元素对应位置不变。
练习:已知一整型数组
a[6]={10,3,9,7,1,5},删除其中最小元素,其余元素对应位置不变。
遍历数组,记录数值最小的元素下标,将这个下标后面的元素都向前移动一个位置
代码示例如下:有帮助望采纳~
#include <stdio.h>
#include<string.h>
int main(int argc, char const *argv[])
{
int a[6] = {10, 3, 9, 7, 1, 5};
int min, loc = 0;
for (int i = 0; i < sizeof(a)/sizeof(int); i++)
{
if (!i)
{
min = a[i];
}
else
{
if (min > a[i])
{
min = a[i];
loc = i;
}
}
}
memcpy(a + loc, a + loc + 1, sizeof(int) * (5 - loc));
for (int i = 0; i < 5; i++)
{
printf("%d ",a[i]);
}
};