#include <stdio.h>
int main() {
int i,j,n,x,flag = 1,a[100];
printf("輸入資料的個數n:");
scanf("%d",&n);
printf("輸入%d個整數:\n",n);
for(i = 0; i < n; ++i)
scanf("%d",&a[i]);
printf("輸入要插入的整數:");
scanf("%d",&x);
for(i = 0; i < n; ++i) {
if(a[i] > x) {
for(j = n; j > i; --j)
a[j] = a[j - 1];
flag = 0;
a[i] = x;
break;
}
if(flag == 1) a[n] = x;
for(i = 0; i <= n; ++i)
printf("%d ",a[i]);
printf("\n");
return 0;
#include <stdio.h>
int main() {
int i,j,n,x,flag = 1,a[100];
printf("輸入資料的個數n:");
scanf("%d",&n);
printf("輸入%d個整數:\n",n);
for(i = 0; i < n; ++i)
scanf("%d",&a[i]);
printf("輸入要插入的整數:");
scanf("%d",&x);
for(i = 0; i < n; ++i) {
if(a[i] > x) {
for(j = n; j > i; --j)
a[j] = a[j - 1];
flag = 0;
a[i] = x;
break;
}
}
if(flag == 1) a[n] = x;
for(i = 0; i <= n; ++i)
printf("%d ",a[i]);
printf("\n");
return 0;
}