I am trying to write a program that fills an array with 11 spots with random numbers between 1-100. It seems like the random stuff works, and the minimum works, but the maximum I am getting crazy high numbers that aren't even part of the 11 numbers that were tossed in the array.
Not quite sure what the problem is, but I am pretty sure it is something ridiculously simple I am looking past.
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main( void )
{
int i = 0;
int a[11];
int min = a[0];
int max = a[0];
srandom( (unsigned) time(NULL) );
for (i=0;i<11;i++)
{
a[i]=random( ) % 100 ;
printf("%d\n", a[i]);
if (a[i] > max)
{
max = a[i];
}
else if (a[i] < min)
{
min = a[i];
}
}
printf("Min: %d\n", min);
printf("Max: %d\n", max);
return ( 0 ) ;
}
OUTPUT:
16
28
27
58
8
53
76
35
27
19
41
Min: 8
Max: 152908968