CTF: Programming Basics
13 challenges — Week 3-4
Programming Basics Challenges
| 13 challenges | Week 3-4 | Week 3 (Advanced Shell Skills and Your First C Program) and Week 4 (C Control Flow) |
Foundational C programming exercises covering console I/O with printf/scanf, function decomposition, escape sequences, function tracing, and basic program composition. These exercises build from “Hello, world!” through interactive programs with variables and user input.
Difficulty Breakdown
| Level | Count |
|---|---|
| Beginner | 10 |
| Intermediate | 3 |
Challenges
1. Hello World
| Difficulty: Beginner | Time: ~2 min | Type: complete program |
Write a complete C program with a main function that prints: Hello, world! (No include statements needed.)
Concepts: main function entry point, printf function for console output, escape sequences (\n for newline), return statement, program structure
2. Basic Function Calls
| Difficulty: Beginner | Time: ~5 min | Type: tracing |
What is the output of the following program? message1 prints ‘This is message1.’, message2 prints ‘This is message2.’ then calls message1 then prints ‘Done with message2.’, main calls message1, message2, then prints ‘Done with main.’
Concepts: function definition and invocation, call stack and function execution order, void functions (functions with no return value), function nesting (calling functions from within functions), execution flow tracking
3. Cat
| Difficulty: Beginner | Time: ~5 min | Type: function |
Write a function named cat that prints a cat figure using /\, ., -, “”
Concepts: escape sequence for backslash (\), escape sequence for quote ("), printf with multiple calls, newline placement (\n), function definition without parameters
4. Egg Figures
| Difficulty: Intermediate | Time: ~15 min | Type: complete program |
Print figures (egg, tea cup, stop sign, hat) using function decomposition with helper functions line(), egg_top(), egg_bottom(), egg(), tea_cup(), stop_sign(), hat()
Concepts: function decomposition and helper functions, code reuse across functions, escape sequences (backslash, quotes), parameter passing (simple int parameters for line width), organized program structure
5. Escape Sequence1
| Difficulty: Beginner | Time: ~5 min | Type: tracing |
What is the output of: printf(“\
“); printf(“‘\n”); printf(“"""\n”);
Concepts: escape sequence for backslash (\), escape sequence for double quote ("), single quote handling in double-quoted strings, escape sequence processing in printf, understanding what the compiler transforms escape sequences into
6. Escape Sequence2
| Difficulty: Beginner | Time: ~5 min | Type: bare code |
Write a statement to produce: / \ // \ /// \\ //// \\
Concepts: escape sequence for backslash (\), pattern recognition in output, multiple backslashes in a single string, alternating forward and back slashes, careful escape sequence counting
7. Escape Sequence3
| Difficulty: Beginner | Time: ~5 min | Type: bare code |
Write statements to generate multi-line output with quotes, backslashes, apostrophes
Concepts: escape sequence for backslash (\), escape sequence for double quote ("), escape sequence for newline (\n), combining multiple special characters, multi-line output generation
8. Function Tracing1
| Difficulty: Beginner | Time: ~3 min | Type: tracing |
What is the output? message1 prints ‘7 ‘, message2 prints ‘5 ‘ calls message1 then prints ‘6 ‘, main calls message1, message2, prints ‘4’
Concepts: function call order and stack discipline, understanding when each function executes, output generation in specific order, execution flow with nested function calls
9. Function Tracing2
| Difficulty: Intermediate | Time: ~5 min | Type: tracing |
What is the output? first prints ‘1 ‘, second prints ‘2 ‘ calls first, third prints ‘3 ‘ calls first then second, main calls second, first, second, third
Concepts: complex function call sequences, nested function calls, understanding call stack behavior, execution order with multiple nesting levels
10. Function Tracing3
| Difficulty: Intermediate | Time: ~7 min | Type: tracing |
What is the output? function_a prints ‘A ‘, function_b calls function_a then prints ‘B ‘, function_c calls function_b then prints ‘C ‘ then calls function_a, main calls function_a, function_b, function_c, function_b
Concepts: complex multi-level function calls, understanding call order with multiple nesting patterns, execution stack with three levels of nesting, careful tracing of sequential and nested calls
11. Receipt
| Difficulty: Beginner | Time: ~5 min | Type: complete program |
Rewrite redundant program to use variables and expressions. Compute subtotal, 8% tax, 15% tip, total.
Concepts: variable declaration and initialization, arithmetic expressions, floating-point calculations, printf with format specifiers (%.02f for currency), code refactoring to reduce redundancy
12. Receipt2
| Difficulty: Beginner | Time: ~7 min | Type: complete program |
Modify receipt program to be interactive — prompt user for meal cost, compute 8% tax, 15% tip.
Concepts: user input with scanf, scanf with format specifier %lf for double, address-of operator (&) in scanf, interactive program design, variable declaration before scanf use
13. Retirement Age
| Difficulty: Beginner | Time: ~5 min | Type: function |
Write retirement_age function that prompts for age, prints years until retirement (65).
Concepts: void functions, user input with scanf, scanf with format specifier %d for int, address-of operator (&) in scanf, variable declaration and arithmetic