I need write a function to check element via bool. I have a random number array function. Return function if there is more than one in a number. Array's range 1 to 100.
My random array function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
int randomarray(int arr[10][10])
{
int i, j;
srand((int)time(0));
for (i = 0; i < 10; i++)
{
cout << endl;
for (j = 0; j < 10; j++)
{
arr[i][j] = rand() % 100 + 1;
cout << arr[i][j] << "\t";
}
}
return arr[10][10];
}
Actually, you don't need to return anything. The array is already being passed as a parameter.
Note, I removed the srand() call from the function, and placed it at the start of main(). The reason for that is to avoid the possibility of calling srand more than once, which usually does not give the expected outcome, it will usually re-seed with the same value and hence generate the same set of numbers all over again.
So, as I understand, you need to create a 2d array, randomize it's elements and then sort the array. Then using a bool type variable, check if the array has duplicate elements and if does, change that elements until they are all different and when all they are different, print the sorted array, am I right?
Yes you are right @nick2361 . I need random and sorted array in output. Both array in output.
And info of how many times return until they are all different.