# include & ltstdlib.h & gt
# include & ltstdio.h & gt
# include & lttime.h & gt
# include & ltmalloc.h & gt
作廢?sx(int?*nums,int?len);//傳遞參數組和長度?函數:升序排列的數組。
作廢?psl(int?*nums,int?len);//打印
int?主()
{
int?n,I,* nums
Printf("輸入n的值(小於等於20):");
scanf("%d ",& ampn);
nums=(int?*)malloc(sizeof(int)*(n+1));
Printf("生成隨機的%d個2位數:",n);
srand(time(NULL));
for(I = 0;我& ltn;i++)
nums[I]= rand()% 100;
sx(nums,n);
printf(" \ n升序後的序列是:");
psl(nums,n);
printf(" \ n輸入要插入的數字:");
scanf("%d ",& ampnums[n]);
sx(nums,n+1);
Printf("插入後的升序為");
psl(nums,n+1);
回歸?0;
}
作廢?psl(int?*nums,int?len)
{
int?我;
for(I = 0;我& ltleni++)
printf("%d?",nums[I]);
}
作廢?sx(int?*nums,int?Len)//傳遞參數組和長度?函數:升序排列的數組。
{
int?nSave,I,j;
for(I = 0;我& ltleni++)
{
for(j = I;j & ltlenj++)
{
if(nums[I]& gt;nums[j])
{
nSave = nums[I];
nums[I]= nums[j];
nums[j]= nSave;
}
}
}
}