对数组进行升序和降序排序

#include
#include
int main()
{
	int i,comp1(),comp2();
	int num[10]={125,-26,53,12,-6,96,46,85,-45,785};
	printf("the original arrat is :\n");
	for(i=0;i<10;i++)
	{
		printf("%10d",num[i]);
	}
	qsort(num, 10, sizeof(int), comp1);
	printf("\n,The accending sorted array is:\n");
	for(i=0;i<10;i++)
	{
		printf("%10d",num[i]);
	}
	qsort(num, 10, sizeof(int), comp2);
	printf("\n The decending sorted arrat is:\n");
	for(i=0;i<10;i++)
	{
		printf("%10d",num[i]);
	}
	return 0;
}
comp1(int *i, int *j)
{
	return *i-*j;
}
comp2(int *i, int *j)
{
	return *j-*i;
}

你可能感兴趣的:(对数组进行升序和降序排序)