解题思路:
注意事项:
参考代码:
#include<stdio.h>
#include<stdlib.h>
int compare(const void* a, const void* b)
{
int num_a = *(int*)a;
int num_b = *(int*)b;
if (num_a < num_b)
return -1;
else if (num_a > num_b)
return 1;
else
return 0;
}
int main()
{
int n, i, a[500], b[500],j=0;
scanf("%d", &n);
for (i = 0; i < n; i++)
{
scanf("%d", &a[i]);
if (a[i] % 2 != 0)
b[j++] = a[i];
}
qsort(b, j, sizeof(int), compare);
for (i = 0; i < j; i++)
{
if (i < j - 1)
{
printf("%d,", b[i]);
}
else
printf("%d", b[i]);
}
return 0;
}
0.0分
0 人评分