1、 有重复数字的彩票程序 #include #include #include int main() { intarr[7] = {},num = 0; srand(time(0)); for(num = 0;num <= 6;num++){ arr[num]=rand() % 36 + 1; } for (num = 0; num<= 6;num++) { printf("%d ", arr[num]); } printf("\n"); return 0; } 2、 没有重复数字的彩票 #include #include #include int main() { int lottery[7] = {}, num = 0, num1 = 0; srand(time(0)); do { lottery[num] = rand() % 36 + 1; for (num1 = 0;num1 <= num - 1;num1++) { if (lottery[num1] == lottery[num]) { break; } } if (!(num1 <= num - 1)) { num++; } } while (num< 7); for (num = 0;num <= 6;num++) { printf("%d ", lottery[num]); } printf("\n"); return 0; } 本文来源:https://www.wddqw.com/doc/3c7ff6b9d4d8d15abe234eb3.html