int example (int num1)
{
if (num1 > 0)
return num1;
if (num1 < 0 )
return -1*num1;
if (num1 == 0)
return 0;
}
How do make it so where there would be only one return statement?
Last edited on
Use the ternary operator.
condition ? ifTrue : ifFalse;
return (num1 >= 0 ? num1 : -num1);