I tried to make a random number generator using arrays and then put it within a range and prevent it from being negative by squaring it but the output still sometimes prints negative numbers. Idk what I'm missing.
#include <stdio.h>
int main()
{
int array[1];
int i = 0;
int number = array[i];
for(i=10; i <= 20; i++){
number = array[i];
printf("%d, ", (number * number) % 21);
}
return 0;
}
output example:
7, 0, 1, 15, 9, -1, 9, 12, 1, 6, 9,