该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
#define N 5
int main()
{
int numbers[N];
int i,j,pre,k;
int x = 5;
int deletenumber; //需要删除的数值
int deleteindex = -1; //需要删除数值的下标
int insertnumber;
for(k=0; k
{
scanf("%d",&numbers[k]);
printf("\n");
}
for(i = 0; i < N; i++)
{
for(j = 0; j < N - i - 1; j++)
{
if(numbers[j] < numbers[j+1])
{
pre = numbers[j];
numbers[j] = numbers[j+1];
numbers[j+1] = pre;
}
}
}
printf("排序后的结果为:\n");
for(i=0;i
{
printf("%d\t",numbers[i]);
}
printf("\n请输入需要删除的数值:\n");
do
{
scanf("%d",&deletenumber);
for(i = 0; i < x; i++)
{
if(deletenumber == numbers[i])
{
//记录当前的下标
deleteindex = i;
break;
}
}
//根据判断语句,执行后续操作
if(deleteindex == -1)
{
printf("请删除正确的数值\n");
}
}while(deleteindex == -1);
for(i = deleteindex; i < x-1; i++)
{
numbers[i] = numbers[i+1];
}
printf("剩下的数值:\n");
for(i=0;i
{
printf("%d\t",numbers[i]);
}
printf("\n请输入0~100的整数:"); //输入一个新的数值,插入数值中并重新排列
getchar();
scanf("%d",&numbers[N-1]);
for(i = 0; i < N; i++)
{
for(j = 0; j < N - i - 1; j++)
{
if(numbers[j] < numbers[j+1])
{
pre = numbers[j];
numbers[j] = numbers[j+1];
numbers[j+1] = pre;
}
}
}
printf("排序后的结果为:\n");
for(i=0;i
{
printf("%d\t",numbers[i]);
}
}