好魔性的題目,我好像中毒了,連睡夢中都會夢到新的解法
我發誓我沒有用迴圈,我用的是 stdlib 的函式,至於 stdlib 用了啥我不知情
(黑心企業標準臺詞)
/* https://ideone.com/J3JKj5 */
#include <stdio.h>
#include <stdlib.h>
int n = 0;
int sort_data[28] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27};
int compare(const void *pa, const void *pb)
{
printf("%d x %d = %d\n", n/8+2, n%8+2, (n/8+2)*(n%8+2));
n++;
return (*((int*)pa) - *((int*)pb));
}
int main(void)
{
qsort(sort_data, 28, sizeof(int), compare);
return 0;
}