I am writing a program that asks the user to enter an integer N and then generates a random array of integers of size 2^N, each of whose entries range from 1 to N+1. The final random array, however, must satisfy the following properties: the integer 1 can be stored in 1 slot, the integer 2 can only be stored in 1 slot, the integer 3 can only be stored in 2 slots, the integer 4 can only be stored in 4 slots... until all 2^N slots are filled with the integers 1, 2, ...,N+1.
I have written some code that asks the user to enter an integer N and then
generates a random array of integers of size 2^N but I cannot generate a random array subject to the constraints that I mentioned above. I have written a function, CheckArray, that returns the value of how many times a certain integer
appears in the array but I don't know how to use it to help me get my desired random array.
Below is the code I have written so far. Note that the function CheckArray is not called in the program since I don't know how to use it yet.
int RandomNumber(int m)
{ // generates a random number in the specified range from 0 to (m-1)
int iSecret;
iSecret = rand() % m + 1;
return(iSecret);
}
int exponentiation(int n)
{ int t;
int numberofcells;
numberofcells = 2;
for(t=1; t < n; ++t)
{numberofcells = 2*numberofcells;}
return(numberofcells);
}
int CheckArray(int IntegerArray[], int sizeOfArray, int CType)
{
int accumulator = 0;
int temp;
for(int i = 0; i < sizeOfArray; i++)
{ temp = IntegerArray[i];
if(temp == CType)
{accumulator++;}