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.
#include
#include
#include
#include
#include
using namespace std;
int RandomNumber(int m);
int exponentiation(int n);
int CheckArray(int IntegerArray[], int sizeOfArray, int CType);
int main()
{ int N;
int NUMOFCELLS;
cout<< "Enter the maximum number of cell divisions you want: ";
cin>>N;
NUMOFCELLS = exponentiation(N);
cout<<"The maximum number of cells will be: ";
cout<
cout<<"n";
int sample[128]; // this reserves 128 integer elements
int t;
srand(time(0));
getchar();
for(t = 0; t <= NUMOFCELLS; t++)
{ sample[t] = RandomNumber(N); }
// display the array
for(t = 0; t < NUMOFCELLS; ++t)
{ cout << sample[t] << ' ' ; }
cout<<"n";
getchar();
return 0;
}
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++;}
}
return accumulator;
}
mails going in spam??
The mails I sent to folks in my database using mail(function) are going in spam??Any idea how I rectify this issue?
Blocking video streaming
Hello everyone,I post a message here because i didn't find any solution yet.I just finished video streaming service on my website. I use xmoov script (http://xmoov.com/xmoov-php/) to do that. It works
CHECK A STRING FOR ' " ' (DOUBLE QUOTES)
I am checking for delimiter (.!?) and if there is a " after a sentence then it should neglect and start from next sentenceI am splitting into two sentences"This is first sentence." This
pagination numbering pattern
Hello,I have following code which works great for pagination. but i have small issue now.Now the output is coming like this Quotemypage.php?page=2I want it like thisQuotemypage.php/2code-Code:
Points for Wiki contribution
Hi everyone,
Help With editting and deleting form
Hallo !!So look at this image :http://img194.imageshack.us/img194/8272/snapshot5f.png This table prints the titles of entries from a table in a database.. The code that i use for this table is this
Alterar a hora do servidor
Se alguém souber, ajude-me a adicionar 6 horas, obrigado<tr> <th>{ov_server_time}</th> <th
FPDF Help
I've been playing with the FPDF module. I was building a form and rolling right along and then suddenly I started getting the "FPDF error: Some data has already been output, can't send PDF
Setting condidtions for an input box
Hi all,I would like to set a condition in a txt box that says the number a user enters has to be in the following format###-#-##-##Would I use PHP to do this or is it part of the HTML form?
Check something, wait, check again, do something!
Hi guys. I wonder if someone can help me with this.Basically, what I want to do is (for arguments sake I will use google.com as an example) check to see if google.com is alive. If its alive, I want it