编写程序,完成如下功能:(1)先询问对多少个数排序? 有效数是2---20,超界重新输入.

来源:百度知道 编辑:UC知道 时间:2024/05/16 12:03:55
2)再选择按升序还是降序排序 3)再输入数据
4)排序并输出
(5)再询问是否进行另一次排序?如回答N结束
程序,否则转(1)

#include<stdio.h>
void sort(int *p,int n)
{
int i,j,swap;
for(i=0;i<n-1;i++)
for(j=0;j<n-i-1;j++)
if(p[j]>p[j+1])
{
swap=p[j];
p[j]=p[j+1];
p[j+1]=swap;
}
}

void main()
{
int n,button,more;
while(1)
{
printf("How much number would you want to sort?\n");

scanf("%d",&n);
while((n<2)||(n>20))
{
printf("Illegal number :) Enter a new number between 2 and 20?\n");
scanf("%d",&n);
}
printf("Do you prefer a greater-list or less-list?\n\nType 1 or 2 to decide.\n");

do
scanf("%d",&button);
while((button!=1)&&(button!=2));

printf("Now it's time to enter your numbers ^-^\n");

int arr[20];
for(int i=0;i<n;i++)
scanf(&