史萊姆論壇

返回   史萊姆論壇 > 專業主討論區 > 程式語言討論區
忘記密碼?
論壇說明

歡迎您來到『史萊姆論壇』 ^___^

您目前正以訪客的身份瀏覽本論壇,訪客所擁有的權限將受到限制,您可以瀏覽本論壇大部份的版區與文章,但您將無法參與任何討論或是使用私人訊息與其他會員交流。若您希望擁有完整的使用權限,請註冊成為我們的一份子,註冊的程序十分簡單、快速,而且最重要的是--註冊是完全免費的!

請點擊這裡:『註冊成為我們的一份子!』

Google 提供的廣告


發文 回覆
 
主題工具 顯示模式
舊 2008-01-04, 05:39 PM   #1
rang0419
註冊會員
榮譽勳章

勳章總數
UID - 285008
在線等級: 級別:0 | 在線時長:4小時 | 升級還需:1小時
註冊日期: 2007-11-07
文章: 24
精華: 0
現金: 35 金幣
資產: 35 金幣
預設 疑問 - 詢問~~將一串數字的 排序&偏移量的程式~~

要怎麼用C寫 排序的程式阿??




那容如下:


1.reads 4 options: -a ascending sorting, -d descending sorting, and -m calculating the mean deviation of array elements and an integer array from the command line;

2. sorts the array and prints the result;

3. calculates the mean deviation of the array elements and prints the result. The mean deviation is defined as Σ |xi - x|/n where x = Σxi/n.
Ex:
x1 = 124, x2 = 234, x3 = 562, x4 = 12 → x = (124 + 234 + 562 + 12)/4 = 233
mean deviation = (|124 - 233| + |234 - 233| + |562 - 233| + |12 - 233|)/4 = 165


Supposed the exectuable code is sort, a possible run may look as follows:



> sort -a 10 28 98 12 47 37 26 58

10 12 26 28 37 47 58 98

> sort -d 10 28 98 12 47 37 26 58

98 58 47 37 28 26 12 10

> sort -m 10 28 98 12 47 37 26 58

The mean deviation is 21.125.

Hint: Refer to the following code:



void selection_sort(int numbers[], int array_size) {

int i, j;

int min, temp;



for (i = 0; i < array_size-1; i++) {

min = i;

for (j = i + 1; j < array_size; j++)

if (numbers[j] < numbers[min]) min = j;

temp = numbers[i];

numbers[i] = numbers[min];

numbers[min] = temp;

}

}

/*

* To run the code, run "sort 10" if the compiled code is "sort".

*/

main(int argc, char *argv[]) {



int a[30];



int a[0] = atoi(argv[1]);

printf("a[0] = %d\n", a[0]);

selection_sort(a, 1);

}


大致上是這樣@@


有哪裡不清楚的地方請和我說一下 拜託一下 各位大了
rang0419 目前離線  
送花文章: 5, 收花文章: 0 篇, 收花: 0 次
回覆時引用此帖
發文 回覆



發表規則
不可以發文
不可以回覆主題
不可以上傳附加檔案
不可以編輯您的文章

論壇啟用 BB 語法
論壇啟用 表情符號
論壇啟用 [IMG] 語法
論壇禁用 HTML 語法
Trackbacks are 禁用
Pingbacks are 禁用
Refbacks are 禁用


所有時間均為台北時間。現在的時間是 01:36 AM


Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2024, Jelsoft Enterprises Ltd.


SEO by vBSEO 3.6.1