How to find max and min both non-zero values from a set of values in an array...
We want max value =11 and min value=2
Please help me out I am stuck here...
NOTICE: 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.
This topic has been locked.
1 reply Latest Post - 2012-12-25T23:28:33Z by SystemAdmin
Pinned topic Non zero minimum value
Answered question This question has been answered.
Unanswered question This question has not been answered yet.
Updated on 2012-12-25T23:28:33Z at 2012-12-25T23:28:33Z by SystemAdmin
SystemAdmin 110000D4XK1883 PostsACCEPTED ANSWER
Re: Non zero minimum value2012-12-25T23:28:33Z in response to SystemAdminYou 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];
StefanoUpdated on 2014-03-26T05:51:41Z at 2014-03-26T05:51:41Z by iron-man