>Any suggestions? thoughts? comments? How do I do this?
Not a bad problem, here's one way:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define LOW 1
#define HIGH 10
#define SIZE 10
#define NPOS SIZE
#define INVAL -1
static int find(int* array, int size, int val)
{
int i;
for (i = 0; i < size; i++)
{
if (array[i] == val)
return i;
}
return size;
}
int main(void)
{
int array[SIZE];
int i = 0;
int r;
srand((unsigned)time(0));
for (i = 0; i < SIZE; i++)
array[i] = INVAL;
while ((i = find(array, SIZE, INVAL)) != NPOS)
{
r = (int)((double)rand() * HIGH) / RAND_MAX + LOW;
if (find(array, SIZE, r) == NPOS)
array[i] = r;
}
for (i = 0; i < SIZE; i++)
printf("%d, ", array[i]);
return 0;
}