1 から 100 までの乱数で配列を 11 個のスポットで埋めるプログラムを作成しようとしています。ランダムなものが機能し、最小値が機能しているように見えますが、最大値は、配列に投げられた11個の数字の一部でさえない非常に高い数字になっています。
問題が何であるかはよくわかりませんが、私が過去を見ているとてつもなく単純なものであると確信しています.
#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 ) ;
}
出力:
16
28
27
58
8
53
76
35
27
19
41
Min: 8
Max: 152908968