@sridhard2406
Let's start by analyzing the original code snippet. The
if statement executes the
then leg if the argument is nonzero or it executes the
else leg if the argument is zero. That is, we return "1" if
flag is nonzero or we return "0" if
flag is zero.
You want to collapse this snippet into a single statement. The one thing we can say with certainty is that if this is possible, then the one statement has to be a
return statement. That is,
Now the problem has shifted to finding an expression that evaluates to "1" when
flag is any nonzero value, and that also evaluates to "0" when
flag is zero. Banfa gave you an important clue in the first reply to this post: "examine all the logical operators". See if you can use the logical operators to construct the necessary expression.
By the way,
@whodgson
I'm afraid this isn't a complete answer because it doesn't provide a way to return "1".