# Thread: How to store Intergers in ARRAY

1. ## How to store Intergers in ARRAY

How do you take the output from rand() and put it into an ARRAY?
This is part of code if you need more I can post it.

Code:
```printf("Maximum digits in the numerator? \n"); //limit a to 3 digits max
scanf("%i",&a);

if (a==2)
{
LIMIT=99;
}
if (a==3)
{
LIMIT=999;
}

srand((unsigned)time(NULL));  	//need 1 a for every c

for (j = 0; j < c; j++)
{
int i = rand() % LIMIT;
printf("The random number is %d\n", i );
}```

2. with LIMIT in all caps you infer that it is a macro like defined like this
#define LIMIT blah
it shouldn't be in caps.
to store it just get the random number then go
Code:
`x=array[j];`
assuming the array is an integer array
Code:
`int array[BUFSIZ];`
do you mean a character array?

3. Yes it is an Interger ARRAY
Here is more of the code.
I changed the LIMIT to limit, it was just a carry over from when it was #defined.

Code:
```#define SIZE 10
int num [SIZE];
int dem [SIZE];

int main(void)
{
int a;//digits in numerator
int b;//digits in demoninator
int c;//number of problems
int j;
int limit;

printf("All answers must be reduced to its simplest form.\n");
start:
printf("\n");
printf("Maximun Number of Problems is 10 \n");
printf("\n");
printf("How many Problems would you like? \n");
scanf("%i",&c);
if (c>10)				//limit c to 10 problems
goto start;

printf("Maximum digits in the numerator? \n"); 	//limit a to 3 digits max
scanf("%i",&a);

if (a==2)
{
limit=99;
}
if (a==3)
{
limit=999;
}

srand((unsigned)time(NULL));  	//need 1 a for every c
for (j = 0; j < c; j++)
{
int i = rand() % limit;
printf("The random number is %d\n", i );
}```

4. An array has three requirements:

1) an array type.
2) an array name.
3) an array size.

Like so:
Code:
`arraytype arrayname [ arraysize ];`
Thus:
Code:
`int somedata[10];`
The array type is of type int.
The array name is 'somedata'.
The array size is 10.

You can access the members of an array by referring to elements 0 through 'arraysize-1'.

Thus in our example, these are valid:
Code:
```somedata[0]
somedata[9]```
And these would be invalid:
Code:
```somedata[-1]
somedata[10]
somedata[400]```
To put a value into an array, by direct assignment, you'd use:
Code:
`somedata[0] = somevalue;`
To get what's stored in the array at a given cell, you use the reverse:
Code:
`somevariable = somedata[0];`
There's a few other items regarding arrays, but the above should suffice.

Quzah.