#include <stdio.h> #include <stdlib.h> int biJiao(int arr[],int len,int key);
int main() {
/*
1~33 随机的产生6个不重复的数
*/ int arr[6] = {0}; for (int i = 0; i < 6;) { int num = arc4random_uniform(33)+1; if (biJiao(arr, 6, num)) { arr = num; i++; } else { printf("%d重复了,重新产生.\n",num); } } for (int i = 0; i < 6; i++) { printf("%d ",arr); } printf("\n");
return 0; } int biJiao(int arr[],int len,int key) { for (int i = 0; i < len; i++) { if (key == arr) { return 0; } } return 1; }
|