- 1

Write a c++ program to check the given number is less than 100 or greater than 100 by using ternary operator

24th Dec 2017, 5:55 PM
Ù…ŰšŰŻŰčŰ© Ű§Ù„Ű„ŰčÙ„Ű§Ù…
Ù…ŰšŰŻŰčŰ© Ű§Ù„Ű„ŰčÙ„Ű§Ù… - avatar
5 Answers
+ 4
( if this question homework)? true : false
24th Dec 2017, 6:01 PM
Morpheus
Morpheus - avatar
+ 2
This will return 0 if num is equal to 100, -1 if num is less than 100, and 1 if num is greater than 100. You can modify the type and values returned to get your desired result. int x = num == 100 ? 0 : (num < 100 ? -1 : 1 );
24th Dec 2017, 7:39 PM
ChaoticDawg
ChaoticDawg - avatar
+ 2
@Martin Taylor I agree. I'm usually verbose with my code to begin with at least and then will refactor it to reduce code size and for optimization etc. I typically write my code in a way that seldom needs comments and will leave it verbose if the refactoring obfuscates the code to a point in which I feel I need a comment to understand it. Given the OP's question I thought this solution would be a decent answer using the ternary operator.
24th Dec 2017, 8:23 PM
ChaoticDawg
ChaoticDawg - avatar