# finding minimum in array

• 12-12-2002
xstudent
finding minimum in array
i have an array (d_available[i])with some zero elements and non zero elements i want to find the minimum of the non zero elements (min_available)

this is what i thought will work but still gives me 0 as minimium
Code:

```min_available=d_available[0] ; for(i=0;i<NROWS;i++){     if (min_available>d_available[i] && d_available> 0)                 min_available=d_available[i];                       }```
• 12-12-2002
Test for the minimum, and if one is found, add a number onto an accumulator.
• 12-14-2002
Ganon of Evil
I believe i see the problem. You have this:
Code:

```min_available=d_available[0] ; for(i=0;i<NROWS;i++){     if (min_available>d_available[i] && d_available> 0)                 min_available=d_available[i];                       }```
It should be this:

Code:

```min_available=d_available[0] ; for(i=0;i<NROWS;i++){     if (min_available>d_available[i] && d_available[i]> 0)                 min_available=d_available[i];                       }```
Does this work?
-Chris
• 12-14-2002
nvoigt
min_available=d_available[0] ;

What if this already is 0 ?

C# Code would look something like this probably:

PHP Code:

``` using System; namespace ConsoleApplication2 {     class Class1     {         [STAThread]         static void Main(string[] args)         {             int[] array = new int[10];             int min = int.MaxValue;             bool found = false;             foreach( int i in array )             {                 if( i > 0 && i < min )                 {                     found = true;                     min = i;                 }             }             if( ! found )              {                 Console.WriteLine( "No nonzero values in array" );             }             else             {                 Console.WriteLine( "The minimum nonzero value was {0}", min );             }         }     } }  ```