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...
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 110000D4XK2130 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];