#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int* makeArray(int n, int xi, int xa)
{
int* x;
int k;
if( (x = (int*)malloc( n * sizeof(int) )) == NULL ) return NULL;
for( k = 0; k < n; k++ )
x[k] = xi + floor( rand() % (xa - xi) );
return x;
}
int getMin(int x[], int n)
{
int i;
int cmin = x[0];
for( i = 1; i < n; i++ )
{
if( cmin > x[i] ) cmin = x[i];
}
return cmin;
}
int main()
{
int n = -1, xMin = -1, xMax = -1;
int res;
int* xarr;
while( n < 1 )
{
printf("Please enter number of elements: ");
scanf("%d", &n);
}
while( xMin < 0 )
{
printf("\nPlease enter minimum value: ");
scanf("%d", &xMin);
}
while( xMax < xMin )
{
printf("\nPlease enter maximum value: ");
scanf("%d", &xMax);
}
if( (xarr = makeArray( n, xMin, xMax )) == NULL )
{
printf("\nError. Can't generate array!\n");
return 1;
}
res = getMin( xarr, n );
printf("\nMinimum value in array is: %d\n", res);
free( xarr );
return 0;
}
这个程序什么意思,每一步什么意思啊