看板 NCTU-STAT98G 關於我們 聯絡資訊
#include <stdio.h> #include <stdlib.h> #include <math.h> int main() { int i,j; int n; //size of data int index; double temp; double *data; printf("Input the size of data:"); scanf("%d",&n); data = (double *) malloc (n*sizeof(*data)); for (i=0;i<n;i++) { data[i] = rand()/32767.0; printf("%lf\n",data[i]); } system("pause"); for (i=0;i<n;i++) { temp = data[i]; index = i; for (j=i;j<n;j++) { if (data[i]>data[j]) { data[i] = data[j]; index = j; } } data[index] = temp; } for (i=0;i<n;i++) printf("%lf\n",data[i]); return 0; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.113.7.248