One of my older C programming books featured a sample program that translated English words into their Pig Latin equivalent. It’s time to revisit this code.
Continue reading
The Double Factorial – Solution
This month’s Exercise is to write code to calculate a double factorial, which uses the !! notation. A double factorial works like a factorial, but uses only odd or even values based on the parity of the starting value.
Continue reading
What is That Defined Constant’s Value?
The C language uses defined constants to represent consistent values across platforms. For example, the PATH_MAX
value might be 260 on one system and 4096 on another. It’s not important to know the specific value, just use the defined constant and your code builds and runs on various systems (hopefully).
Continue reading
The Double Factorial
Difficulty: ★ ★ ☆ ☆
It’s common in programming to use a factorial as a way to teach about recursion. For example, 5! (five factorial) is 5×4×3×2×1, which is 120. Calculating this result can be done with a recursive function, which is practical and satisfying. But mathematicians have a twisted sense of humor, so they invented something called a double factorial.
Continue reading
Sorting the Hexwords, Part II
The problem with the code from last week’s Lesson is obvious: The decimal value of FEED is 1,044,205, not 2,314,885,530,818,453,605 as shown in the output. Before I can sort the list numerically, this error must be addressed.
Continue reading
Sorting the Hexwords, Part I
The Linux dictionary stores its words sorted alphabetically. Therefore, the output from the program presented in last week’s Lesson shows valid hexwords (letters A through F, four letters or longer) in alphabetic order. But what if I want the words output in numerical order?
Continue reading
The HexWord Tally and Total
The dictionary is full of words composed of only the letters A through F, which are also hexadecimal digits. These English language hexwords can be pulled from the computer’s digital dictionary, which was demonstrated in last week’s Lesson. Time to update the code!
Continue reading
HexWords
Hexadecimal, or counting base 16, uses letters A through F to represent values 11 through 15. This base — “hex” — is common in programming as it works as a shorthand for binary values. But the letters used are also letters, which means that they can spell words.
Continue reading
Ethiopian Multiplication – Solution
The challenge for this month’s Exercise is to write code that uses the Ethiopian Multiplication method. The process involves doubling and halving the factors, then eliminating and finally tallying the result.
Continue reading
Testing For the random() Function
Silly me. I once assumed that just because my compiler offered the random() function — a superior version of the C library standard rand() function — that every compiler fatured this function. Boy, was I wrong!
Continue reading