liveBook · Manning

Odd integer

As explained in Learn C++ by Example

An odd number is an integer that is not evenly divisible by two.

An odd integer leaves a nonzero remainder when divided by two. In C++, testing i % 2 identifies odd values and distinguishes them from even values. section 9.1.4

Marking odd and even triangle numbers

A transformation turns odd triangle numbers into dots and even ones into asterisks: . . * * . . * *. The lambda returns '.' when i % 2 is nonzero and '*' otherwise. section 9.1.4

How Learn C++ by Example covers it

How deep it goes
Defines oddness operationally through a nonzero i % 2 result, without developing a broader mathematical treatment.
Examples
Uses triangle numbers, dot-and-asterisk markers, and a C++20 ranges transformation.
What it assumes
Assumes integers, modulo syntax, lambdas, and range algorithms.
What you can do after
Apply it via the modulo operator to classify integers and transform collections into printable markers.
How it connects
Connects odd integers with even integers, parity, triangle numbers, and range algorithms.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn C++ by Example. The section links point to the parts of the book it draws on.