#include<stdio.h>
int main() {
int a[] = { 1,3,6,10 };
int b[100] = { 0 };
int len = sizeof(a) / sizeof(a[0]);
int n;
scanf_s("%d", &n);
int i=0;
int t=0;
if (n > a[len - 1]) {
for (int j = 0; j < len; j++) {
b[j] = a[j];
}
b[len] = n;
}
else {
while (i < len) {
while (a[i] < n) {
b[i] = a[i];
i++;
t = i;
}
while (a[i] >= n) {
b[i + 1] = a[i];
i++;
}
}
b[t] = n;
}
for (int j = 0; j <=len; j++) {
printf("%d ", b[j]);
}
}
#include<stdio.h>
//向后移
int main() {
int a[] = { 1,3,6,10 };
int len = sizeof(a) / sizeof(a[0]);
int n;
scanf_s("%d",&n);
int i;
if (a[len - 1] < n) {
a[len] = n;
}
else {
for (i = 0; i < len; i++) {
if (n < a[i]) {
break;
}
}
for (int j = len; j >=i; j--) {
a[j+1] = a[j];
}
a[i] = n;
}
for (int i = 0; i <=len; i++) {
printf("%d ", a[i]);
}
return 0;
}
ps:不知道为啥第二个vs总是出现数组越界,但是结果也是对的-_-||