Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - C language programming: define a two-dimensional integer array with 4 rows and 5 columns, randomly assign values to each element, and find out the minimum value and its subscript.
C language programming: define a two-dimensional integer array with 4 rows and 5 columns, randomly assign values to each element, and find out the minimum value and its subscript.
First, initialize the random number generator, and then assign a value to the two-dimensional integer array. Find out the minimum number by gallants method when assigning the value, update and record its subscript after finding the minimum number, and output the values of subscript and minimum number at the end of the loop.

# include & ltstdio.h & gt

# include & ltstdlib.h & gt

# include & lttime.h & gt

int main()

{ int i,j,i0=0,j0=0,a[4][5];

srand(time(0));

for(I = 0; I<4; i++)

{ for(j = 0; j & lt5; j++)

{ a[I][j]= rand()% 100+ 1;

? printf("%4d ",a[I][j]);

? if(a[I][j]& lt; a[i0][j0])

? { i0 = I;

j0 = j;

? }

}

printf(" \ n ");

}

Printf ("the minimum value is a [%d] [%d] =% d \ n", i0, j0, a [i0] [j0]);

Returns 0;

}