liveBook · Manning

Parity

As explained in Learn C++ by Example

Parity is the classification of an integer as odd or even.

Parity classifies an integer as odd or even. Testing i % 2 gives a nonzero result for odd numbers and zero for even numbers. section 9.1.4

Marking triangle numbers

A C++ ranges transformation converts triangle numbers into characters: '.' marks odd values and '*' marks even values. The output reveals a repeating pattern of two odd numbers followed by two even numbers. section 9.1.4

How Learn C++ by Example covers it

How deep it goes
Defines modulo-2 testing and demonstrates it in a ranges pipeline, without developing a formal theory of parity.
Examples
Uses triangle numbers, dot-and-star markers, repeating output, and final-digit frequency counts.
What you can do after
Apply it via C++ remainder checks and ranges transformations to label numbers as odd or even.
How it connects
Connects parity with triangle numbers, the modulo operator, ranges algorithms, output iterators, and digit tallies.

Also explained in

Compare how 2 books explain parity →

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.