# finding minimum in array

This is a discussion on finding minimum in array within the C# Programming forums, part of the General Programming Boards category; i have an array (d_available[i])with some zero elements and non zero elements i want to find the minimum of the ...

1. ## 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];

}```

2. Test for the minimum, and if one is found, add a number onto an accumulator.

3. 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

4. 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 );             }         }     } }  ```