You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
470 B

#include<iostream>
using namespace std;
int main() {
int num = 0;
int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
scanf("%d", &num);
int end = 8;
while (end >= 0 && num < array[end]) {
array[end + 1] = array[end];
end--;
}
array[end + 1] = num;
printf("插入元素%d之后的结果为:\n", num);
for (int i = 0; i < 10; ++i)
printf("%d ", array[i]);
printf("\n");
return 0;
}