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
1 |
|
Greatest common divisor
1 | static long long gcd(long long a, long long b) { |
Decode a character string
When a problem defines a fixed substitution, keep the transformation explicit and preserve characters outside the intended range:
1 | for (size_t i = 0; text[i] != '\0'; ++i) { |
Pascal’s triangle
1 | triangle[0][0] = 1; |
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.