Simplifying Fractions

Difficulty: ★ ★ ★ ☆

Recently, I wrote code to calculate odds. The program’s output listed the odds as a fraction, such as 1/6 for rolling a specific number on a die. But occasionally, the output is something like 7/21. As a human, and after a modicum of mental sweat, I recognize 7/21 as 1/3. The challenge is how to get the computer to recognize and report the smaller fraction.
Continue reading

Variable Scope

In C programming, variables declared within a function are local to the function. Specifically, they’re the auto storage class, the default. External, or global, variables are defined outside of a function declaration and are of the extern storage class. These variables are available to all functions. But the scope within a function can also be limited, depending on where the variable is declared.
Continue reading