所以我试图随机化1,2,3,4,5,6,7,8,9,10的数组。然后要求用户在数组中选择一个位置,并修改它。之后,它应该显示用户输入的数字全部的10个值。最后,它需要获得随机化的原始数组并将其逆转。随机化/修改数组
到目前为止,我有这个
#include <iostream>
using namespace std;
int array [10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int rarray [10];
int main() {
cout << "Random Array = ";
for (int i = 0; i < 10; i++) {
int index = rand() % 10;
int temp = array[i];
array[i] = array[index];
array[index] = temp;
}
for (int i = 1; i <= 10; i++) {
cout << array[i] << " "; //somehow, this display needs to be entered into another array
}
system("PAUSE");
}
但正如评论所说,我卡上,如何做到这一点。
C++中的数组使用基于零的索引,而不是一个基于索引。 ['std :: shuffle'](http://en.cppreference.com/w/cpp/algorithm/random_shuffle)和['std :: reverse'](http://en.cppreference.com/w/cpp /算法/反向)是你的朋友。 – 2014-10-26 23:54:54
请将问题的范围缩小到您遇到问题的特定部分。 – 2014-10-27 00:10:09