Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
1 reply Latest Post - ‏2012-12-25T23:28:33Z by SystemAdmin
SystemAdmin
SystemAdmin
1883 Posts
ACCEPTED ANSWER

Pinned topic Non zero minimum value

‏2012-12-25T19:31:58Z |
How to find max and min both non-zero values from a set of values in an array...

Ex: A=0,2,0,5,8,0,11

We want max value =11 and min value=2
Please help me out I am stuck here...

Thank You
Updated on 2012-12-25T23:28:33Z at 2012-12-25T23:28:33Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    1883 Posts
    ACCEPTED ANSWER

    Re: Non zero minimum value

    ‏2012-12-25T23:28:33Z  in response to SystemAdmin
    You can use the min and max operators with a conditional statement in their scope:

    range R = 1..7;
    int A[R] = [0, 2, 0, 5, 8, 0, 11];
     
    int minA = min(r in R : A[r] != 0) A[r];
    int maxA = max(r in R : A[r] != 0) A[r];
    


    Regards,
    Stefano
    Updated on 2014-03-26T05:51:41Z at 2014-03-26T05:51:41Z by iron-man