# min()function

• 09-27-2005
rina
min()function
Hi all.
I have a problem in programming a function to select minimum values which are stored in an array. The parameter of the min function are dynamic values.
For mow, I have an example on how to determine minimum value between 2 or 3 parameters. I need to create a function that can receive more than 3 parameters. I want to determine min value for each column in my two dimensional array as below.

1.00 0.00 2.83 4.24
5.00 4.24 1.41 0.00
3.65 0.71 2.34 4.61
4.30 0.00 0.50 3.20
3.21 3.54 1.00 4.53

The problem is to determine min value for each column.
Can anyone here give me some ideas how to do this?

• 09-27-2005
quzah
First, write a program that will take a single dimension array, and find the minimum value in it. That should get you started.

Quzah.
• 09-28-2005
rina
Hi all.

I have this function like below to determine the min value for each column.
But it doesnt work. The output seems right but not in the order of the array.

I have an array euc_total[cluster][i] which stores data like below:
1.0000 0.0000 2.8300 4.2400
5.0000 4.2400 1.4142 0.0000

My function:
Code:

```void minimum_distance() {         double min = 0.0;         for ( i = 0; i < ROW; i ++ )         {                 for (cluster = 0; cluster < cluster_num; cluster++)                 {                         if (euc_total[cluster][i] < euc_total[cluster + 1][i])                                 min = euc_total[cluster][i];                         else                                 min = euc_total[cluster + 1][i];                                         }                 printf("\n %.4f",min);         } }//```
My output:
1.4142
0.0000
1.0000
0.0000

The output should be like:
column 1: 1.0000
column 2: 0.0000
column 3: 1.4142
column 4: 0.0000

Can anyone help?
• 09-28-2005
quzah
Multi-dimensional arrays are indexed like so:
Code:

```int array[ X ]; int twodee[ Y ][ X ]; int threedee[ Z ][ Y ][ X ];```
Thus:
Code:

```int twodee[ ROWS ][ COLS ]; int y, x; for( y = 0; y < ROWS; y++ )     for( x = 0; x < COLS; x++ )         printf("twodee[ %d ][ %d ] is %d\n", y, x, twodee[ y ][ x ] );```
Actually, since you want the information for each column, you'd do:
Code:

```for( x = 0; x < COLS; x++ )     for( y = 0; y < ROWS; y++ )         if( minimum > twodee[ y ][ x ] )             minimum = twodee[ y ][ x ];```
Or something akin to that.

Quzah.
• 09-28-2005
ZuK
Quote:

Originally Posted by rina
Code:

```                if (euc_total[cluster][i] < euc_total[cluster + 1][i])                                 min = euc_total[cluster][i];                         else                                 min = euc_total[cluster + 1][i];                                         }```

You are accessing values that do not belong to the right cluster.