#include
#include
#include
using namespace std;
int main()
{
int a[5];
int temp;
srand((unsigned)time(0));
for (int i = 0;i < 5;i++)
{
temp = 1 + rand() % 5;
for (int j = 0;j <= i;j++)
while (temp == a[j])
{
temp = 1 + rand() % 5;
j = 0;
}
a[i] = temp;
cout << a[i] << " ";
}
cout << endl;
return 0;
}
给他们加分吧,随机数取模
先产生随机数x,y=x%5,y等于几就显示第几个,重复的跳过。