In an alternative universe, the C programming language lacks a modulus operator and no companion function exists in the library. What to do! Why, you code your own modulus function, which is the challenge for this month’s Exercise.
Continue reading
Building a String
Programming language more modern than C sport great libraries of functions, or “methods.” Java has so many I doubt that a single programmer knows them all. In C, however, when a function is absent (and a lot of them are, comparably), you must code your own. Such is the case with building a string.
Continue reading
Emulating the Modulus Operator
Difficulty: ★ ★ ☆ ☆
I think any kid learning math in school knows what a remainder is, but few understand (or are taught) what a modulus is. It obtains the remainder of one value divided by another, specifically a larger value divided by a smaller value. In C programming, the % (modulo) operator performs this calculation. But what if the C language lacked a modulo operator?
Continue reading
The Pig Latin Translator, Part III
The final step in my Pig Latin journey is to process an entire English language sentence. The piglatin() function, finished in last week’s Lesson, requires no updates. But chopping a sentence into words and sending them off to be processed individually proved to be an interesting exercise.
Continue reading
The Pig Latin Translator, Part II
From last week’s Lesson, the piglatin() function swallows a word and returns its Pig Latin translation, but only for words starting with a vowel. The operation for words that begin with a consonant is more complex.
Continue reading
The Pig Latin Translator, Part I
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