c语言中给定一个已知数组使他和另一个随机6个数的数组相乘得到的乘积不能重复,输出那6个未知数数

发布时间:2019-07-29 17:22:24

c语言中给定一个已知数组使他和另一个随机6个数的数组相乘得到的乘积不能重复,输出那6个未知数数

推荐回答

/*a[1] = 36a[7] = 38a[3] = 13a[6] = 95a[8] = 54Press any key to continue*/#include <stdio.h>#include <stdlib.h>#include <time.h>int main() {int a[10] = {12,36,52,13,30,87,95,38,54,19};int b[10] = {0}; // 全部初始化为0int i,t,n = 10,m = 5;srand((unsigned)time(NULL));for(i = 0; i < m; ++i) { // 随机显示5个数组元素t = rand()%n;if(b[t] == 0) {b[t] = 1;printf("a[%d] = %d\n",t,a[t]);}else i--;}return 0;}

以上问题属网友观点,不代表本站立场,仅供参考!