C Programming Exercises, Part 1: Strings, Arrays, Dates and Number Theory
This first exercise collection progresses from simple input and arithmetic to arrays, strings, calendar calculations, and dynamic programming. Each solution should validate input, use a sufficiently wide type, and compile without warnings.
Subtract two integers
Greatest common divisor
Decode a character string
When a problem defines a fixed substitution, keep the transformation explicit and preserve characters outside the intended range:
Pascal’s triangle
The full set also includes selecting the heaviest apple, exchanging bottles, string comparison and copying, Josephus counting, weekday calculation, digit filtering and reversal, age grouping, fraction-series sums, matrix saddle points, longest words, longest increasing subsequences, day-of-year calculation, and tiered bonuses.
For every exercise, write down the invariant before coding and test minimum, maximum, duplicate, and malformed cases. Prefer fgets plus parsing for free-form text, avoid unbounded %s, and enable -Wall -Wextra -Wpedantic while learning.