我有这个代码......对于一个函数,它从用户那里获取 7 个数字并将其放入数组 1 中......然后创建一个随机数并将它们放入数组 2 中......检查是否有共同值...(不仅在同一个地方,例如:不仅如果 ar1[1]==ar2[1] ...而且检查所有地方是否存在共同值)...。将不同的值放在第三个数组中...创建第三个数组并将不常见的值放入其中...这是我的代码:
//includes
# include <stdio.h>
# include <conio.h>
# include <stdlib.h>
# include <time.h>
//define
#define N 7
//prototype
void randomArray(int maxVal,int ar2[]);
int main()
{
//variables/arrays
int ar1[N],ar2[N],ar3[N],i,z,t,temp,maxVal,counter;
printf("Please Enter %d numbers: ",N);
for(i=0;i<7;i++)
{
scanf("%d",&ar1[i]);
}
while(1)
{
printf("Please enter a max value: ");
scanf("%d",&maxVal);
if(maxVal>0)
break;
}
randomArray(maxVal,ar2);
getch();
return 0;
}
//randomArray
void randomArray(int maxVal,int ar2[])
{
int i;
for(i=0;i<N;i++)
{
/* get random value between minVal and maxVal */
ar2[i] = (rand() % (maxVal+1 - 1)) + 1;
}
}