-2
我的教練把我們負責編制,我們做一個選擇排序的代碼在C,像這樣的一個我在網上找到一個代碼,選擇排序編號
#include <stdio.h>
int main()
{
int array[100], n, c, d, position, swap;
printf("Enter number of elements\n");
scanf("%d", &n);
printf("Enter %d integers\n", n);
for (c = 0 ; c < n ; c++)
scanf("%d", &array[c]);
for (c = 0 ; c < (n - 1) ; c++)
{
position = c;
for (d = c + 1 ; d < n ; d++)
{
if (array[position] > array[d])
position = d;
}
if (position != c)
{
swap = array[c];
array[c] = array[position];
array[position] = swap;
}
}
printf("Sorted list in ascending order:\n");
for (c = 0 ; c < n ; c++)
printf("%d\n", array[c]);
return 0;
}
而是輸入數字數組的,我們必須使用srand()
命令來生成一組隨機數。
我已經在它約4小時了,我似乎無法得到它。
請我真的需要幫助使用srand()
和rand()
您使用有用['函數srand ()'](http://en.cppreference.com/w/c/numeric/random/srand)播種隨機數發生器(**一次**)。你可以使用['rand()'](http://en.cppreference.com/w/c/numeric/random/rand)來實際生成數字。我在代碼中看不到任何內容,因此我不確定過去四個小時內發生了什麼。 – WhozCraig 2015-03-19 07:22:56
你的老師,可憐的傢伙! – 2015-03-19 08:28:44