Overview
This module builds on the fundamentals of functions and loops, introducing more complex nested loop patterns, character validation functions, and practical exercises like the FizzBuzz problem. You’ll create functions that draw shapes and validate character types.Function prototypes
Themain.h header file defines the following function prototypes:
main.h
Character validation functions
Checking for uppercase characters
The_isupper() function checks if a character is uppercase by comparing its ASCII value:
0-isupper.c
ASCII values 65-90 represent uppercase letters A-Z. This function returns 1 (true) if the character is uppercase, 0 (false) otherwise.
Checking for digits
Similar to_isupper(), the _isdigit() function validates whether a character is a numeric digit (0-9).
Mathematical operations
Simple multiplication
2-mul.c
Pattern printing with nested loops
Drawing squares
Theprint_square() function uses nested loops to draw a square of a given size:
8-print_square.c
How the nested loop works
How the nested loop works
The outer
while loop controls the rows (running n times), while the inner while loop prints n hash characters for each row. The special case handles when n <= 0 by printing a single newline.Drawing triangles
Theprint_triangle() function creates a right-aligned triangle pattern:
10-print_triangle.c
This function demonstrates how to create patterns with both spaces and characters. For each row
i, it prints (size - i) spaces followed by i hash characters, creating a right-aligned triangle.The FizzBuzz challenge
FizzBuzz is a classic programming interview question that tests your understanding of conditionals and loops:9-fizz_buzz.c
FizzBuzz rules
Check divisibility by both 3 and 5
If the number is divisible by both 3 and 5 (i.e., divisible by 15), print “FizzBuzz”
Key concepts
Character validation
Use ASCII value ranges to validate character types (uppercase, digits, etc.)
Nested loops
Combine multiple loops to create 2D patterns and shapes
Conditional logic
Order your conditionals carefully, especially when checking multiple conditions
Pattern building
Break complex patterns into rows and columns, handling each with separate loop iterations
Compilation
Compile these programs with the standard flags:Next steps
Pointers & arrays
Move on to memory addresses and pointer manipulation
Debugging
Learn debugging techniques for C programs