C Programming
Beginner
C Programming
Learn C from Hello, World! to loops, arrays, structs and random numbers, with worked examples, practice problems and hints.
📚 What you'll learn
- Write, compile and run C programs with gcc.
- Choose the right variable types and operators.
- Control program flow with if, switch and every kind of loop.
- Store data in arrays and group it in structs.
- Validate user input and generate random numbers.
7modules
19lessons
2.7 hoursof content
0quiz questions
🧰 Requirements
- A computer with gcc installed (or an online C compiler).
- No prior programming experience needed.
Course content
Module 1Getting Started
Write, compile and run your first C programs.
1.1C's "Hello, World!" Explained Line by Line (for R & Python Users)A line-by-line breakdown of the classic C Hello World program — what each part does, why C requires it, and how it compares to Python and R.1.2How to Test a Small C Snippet QuicklyThe fastest ways to try a few lines of C: online compilers, a one-line gcc build-and-run command, editor shortcuts, and feeding input from a file.
Module 2Variables and Data Types
Declare variables and choose the right numeric type.
2.1Declaring Multiple Variables in One Line in CHow to declare several C variables in one statement (int a, b, c;), initialise them, and avoid the traps: partial initialisation, the pointer asterisk, mixed types and chained assignment.2.2float vs double in C: Precision, Memory, and When to Use WhichHow C's float and double differ in precision, size, range, literals and format specifiers, with real compiler output showing where float goes wrong.
Module 3Operators and Input
Increment operators and reading input safely.
3.1Pre-Increment vs Post-Increment in C: ++i vs i++The difference between ++i and i++ in C: when the value changes, what the expression returns, with compiled examples, and why it only matters inside larger expressions.3.2Checking User Input in C: Is It Really a Number?How to check that user input is a valid integer in C, using scanf's return value and a stricter fgets + strtol check, with a factorial example.
Module 4Making Decisions
Branch with if, the ternary operator and switch.
4.1Nested if in C, Explained with Real-Life ExamplesWhat a nested if statement is in C, when the inner check runs, and two worked examples (a store discount and an ATM withdrawal) with flowcharts, code and common pitfalls.4.2Shortcut Ways to Write if in C: the Ternary Operator and MoreShorten an if to one line by dropping the braces, write an if-else with the ternary operator ?:, and use other shortcuts: testing a value directly and using a comparison as a number. With short examples and their real output.4.3The switch Statement in C: Syntax, break, Fall-Through and ExamplesHow C's switch statement works: matching cases, break, default, deliberate fall-through, grouped cases, chars and enums, and when to choose switch over if / else if.
Module 5Loops
Repeat work with while, do-while and for, then practise.
5.1The do-while Loop in C: Run First, Check AfterHow C's do-while loop works: the body always runs at least once before the condition is tested. Two PIN-entry examples, plus do-while vs while and common pitfalls.5.2Why Use break in a while Loop If the Condition Already Stops It?If a loop runs while i < 10 but breaks at 4, why write i < 10 at all? The condition is the planned exit and break is the exit for a special case. Four short examples: search, sentinel input, retries and menus.5.3Printing a Comma-Separated List in C (No Trailing Comma, Clean Line Breaks)How to print 0, 1, 2, ... with commas in C: why a plain printf glues the numbers together, four ways to avoid the trailing comma, and how \n works in nested loops for rows of numbers.5.45 while Loop Practice Problems in C (with Hints and Solutions)Five while-loop exercises in C, from printing even numbers to reversing a number: each with a task, expected output, a step-by-step hint, a tested solution, and a harder follow-up.5.55 for Loop Practice Problems in C (with Hints and Solutions)Five for-loop exercises in C, from a multiplication table to a star triangle: each with a task, expected output, a step-by-step hint, a tested solution, and a harder follow-up.5.65 Nested for Loop Practice Problems in C (with Hints and Solutions)Five nested for-loop exercises in C: a rectangle, a multiplication grid, a number triangle, a centred pyramid and a checkerboard. Each has expected output, a hint and a tested solution you can reveal.
Module 6Arrays and Structs
Store many values, and group related ones.
6.1How to Save Loop Results in an Array in CDeclare a fixed-size array, fill it with a for loop using the loop index, and grow it with malloc() and realloc() when the number of values is not known in advance.6.2Structs in C: Grouping Related Data (with Python and R Comparisons)How C structs group different types into one unit: student records, arrays of structs, points, linked-list nodes, typedef, ->, padding, and how structs compare with Python dicts and R lists.
Module 7Random Numbers
Generate and analyse random values.
7.1srand(time(NULL)) in C: Why Random Numbers Repeat and How to Seed ThemWhat srand(time(NULL)) really does: why rand() repeats the same numbers without a seed, how time(NULL) fixes that, the unsigned cast, the same-second trap, and why we seed only once.7.2Tossing a Die in C Until We Get a 6Track every roll of a die in C: print as we go, store the history in an array, tally frequencies, and list which steps produced each face.
AA
Abdullah Al Mahmud
Stat Mania
Stat Mania builds free, hands-on statistics and programming courses.
0%
0 of 19 lessons
- Modules and lessons
- Practice problems with hints
- Saved progress, no account
- Works on phones
Progress is saved in this browser only.
Back to top