To solve this month’s Exercise, you must create a function that tallies digits in an integer value, what’s known as a digit sum. The key issue is how to peel off individual values in an integer and then total the result.
Continue reading
Category Archives: Solution
Find the Best Size Container – Solution
The C library contains various mathematical rounding functions, such as ceil(). That function, however, rounds up floating point values to the next integer. For this month’s Exercise, your job was to round up an integer to multiples of 16: 16, 32, 48, and 64.
Continue reading
Off to the Races – Solution
The purpose of the winner() function in the horse race game is to determine which value in an integer array is the largest. That would be an easy exercise to write, but it lacks the thrill and excitement of a horse race.
Continue reading
Read a Percentage Value – Solution
One of the things I enjoy about coding defensive input is that I get to think about all the oddball possibilities. Users can type anything, which is something you must always anticipate. For typing in a percentage value, the door for whacky input is left wide open.
Continue reading
Appreciation for Depreciation – Solution
This month’s Exercise is one of those old, programming warhorses: Calculate a depreciation schedule. At the simplest level, the solution is a mathematical loop and keeps subtracting a given percentage from a value.
Continue reading
Text Parsing Power – Solution
This month’s Exercise hosts a realm of possible solutions. So I present you with my three solutions, two of which are general and one specific.
Continue reading
Defensive Input – Solution
Writing an input routine isn’t that difficult in C. I cobble together simple input routines all the time. The scanf() function is brilliant for such situations. When you have to test input, things get dicey, which I hope you discovered as you attempted this month’s exercise.
Continue reading
Merry Cumulative Song Exercise – Solution
I crafted my solution to the cumulative song exercise by separating the parts of the song that are repeated from the unique text. Specifically, the ordinal days are unique as well as the gifts. The rest of the text is sung over and over.
Continue reading
Hex Parsing – Solution
Two solutions are possible for this month’s Exercise, a string solution and a value solution. One is good for parsing the hex string right-to-left, the other for parsing the string left-to-right.
Continue reading
The Hailstone Sequence – Solution
My solution to this month’s Exercise is split into two main parts. The first part generates the random value in the range of 1 to 100. The second part performs the Hailstone sequence on that value.
Continue reading