第1个回答 2018-02-12
#include<stdio.h>
#include<string.h>
//快速排序
int Partition_1(int arr[],int low,int high)
{
int pivotloc=arr[low],temp;
while(low<high)
{
while(low<high&&arr[high]>=pivotloc)
--high;
temp=arr[low];
arr[low]=arr[high];
arr[high]=temp;
while(low<high&&arr[low]<=pivotloc)
++low;
temp=arr[low];
arr[low]=arr[high];
arr[high]=temp;
}
return low;
}
void QSort(int *arr,int n,int low,int high)
{
int pivotloc;
if(low<high)
{
pivotloc=Partition_1(arr,low,high);
QSort(arr,n,low,pivotloc-1);
QSort(arr,n,pivotloc+1,high);
}
}
void QuickSort(int *arr,int n)
{
QSort(arr,n,0,n-1);
}
int main()
{
int arr[]={1,3,5,4,6,2,7,9,8,0};
int i=0;
QuickSort(arr,10);
printf("最大值:%d\t最小值:%d\n",arr[9],arr[0]);
return 0;
}
第2个回答 2015-11-22
#include<stdio.h>
void main()
{ int max,min,x,n;
printf("请输入第1个数:");
scanf("%d",&x);
max=min=x;
for(n=2;n<=10;n++)
{printf("请输入第%d个数:",n);
scanf("%d",&x);
if(x>max) {max=x;continue;}
if(x<min) min=x;
}
printf("最大数是:%d\n最小数是:%d\n",max,min);
}本回答被网友采纳