该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
/*通过double指针从用户那里获得10个数字,然后对他们进行排序,并将它们打印到屏幕上*/
#include
#include
#define N 10
void paixu( double *b[] );
void print( double **b );
void free_memory( double *b[]);
int main( void )
{
double *a[N];
printf("\n请输入十个数\n");
for( int i = 0; i < N; i++)
{
a[i] = (double *)malloc(sizeof(double));
if( !a[i] )
{
printf("ERROR");
exit(-1);
}//malloc分配不成功退出
scanf("%f",a[i]);
}
paixu(a);
print(a);
free_memory(a);
system("pause");
return 0;
}
void paixu( double *b[] )
{
int c,i,j;
double *tmp;
printf("\n从大到小排序请按0,从小到大排序请按1\n");
scanf("%d", &c);
if( c==0 )
{
for(i=0; i
{
for(j=0; j
{
if(*b[j] < *b[j+1])
{
tmp = b[j];
b[j] = b[j+1];
b[j+1] = tmp;
}
}
}
}
if( c==1 )
{
for(i=0; i
{
for(j=0; j
{
if(*b[j] > *b[j+1])
{
tmp = b[j];
b[j] = b[j+1];
b[j+1] = tmp;
}
}
}
}
}
void print( double *b[])
{
for( int i = 0; i
printf("%lf\n",*b[i]);
}
void free_memory( double *b[])
{
for( int i = 0; i
free(b[i]);
}