Write a program that produces 20 random numbers between 1 and 20. The program should store all nonduplicate values in an array.
Use the smallest possible array to accomplish this task.
I can get the numbers generated no problem however, i can't get my program to check against the array to se if the value has been stored or not...
Here is my code thus far:
Code:
#include <stdlib.h>
#include <stdio.h>
#define val 20 /*variable to be stored in the array*/
int main()
{
int i,x;
int array[val];
for ( i = 1; i <= 20; i++ )
{
x = 1 + (rand() % 20);
array[val]=x;
printf("%d", array[val]);
printf("\n");
}
printf("\n");
return 0;
}
[edit]Code tags added by Hammer.