From the course: Advanced C Programming: Optimize Performance and Efficiency

Unlock the full course today

Join today to access over 24,500 courses taught by industry experts.

Solution: A ternary-operator decision

Solution: A ternary-operator decision

(upbeat music) - [Instructor] Here's my solution to the challenge. Lines seven and eight gather input, prompting for a positive integer greater than zero and reading it into variable v. I added lines 10 and 11 to ensure that the value returned is within the parameters asked for. This checking is optional, though, give yourself a star if you also thought of such checking. The solution I'm asking for is found at line 15, with the ternary operator. The value of variable v is manipulated by using the modulus operator. It returns the remainder of v, divided by two, which is going to be either zero or one. If one, the string, odd, is generated. Otherwise, the string, even, is generated. The string is then placed into the printf function, where the %s sits. Similar solutions are also popular. Although, you need to use the ternary operator in some way, to pass this challenge.

Contents