Stat Mania
  • C Programming
  • All Courses
  1. Course Home
  • Course Home
  • Getting Started
    • C's "Hello, World!" Explained Line by Line (for R & Python Users)
    • How to Test a Small C Snippet Quickly
  • Variables and Data Types
    • Declaring Multiple Variables in One Line in C
    • float vs double in C: Precision, Memory, and When to Use Which
  • Operators and Input
    • Pre-Increment vs Post-Increment in C: ++i vs i++
    • Checking User Input in C: Is It Really a Number?
  • Making Decisions
    • Nested if in C, Explained with Real-Life Examples
    • Shortcut Ways to Write if in C: the Ternary Operator and More
    • The switch Statement in C: Syntax, break, Fall-Through and Examples
  • Loops
    • The do-while Loop in C: Run First, Check After
    • Why Use break in a while Loop If the Condition Already Stops It?
    • Printing a Comma-Separated List in C (No Trailing Comma, Clean Line Breaks)
    • 5 while Loop Practice Problems in C (with Hints and Solutions)
    • 5 for Loop Practice Problems in C (with Hints and Solutions)
    • 5 Nested for Loop Practice Problems in C (with Hints and Solutions)
  • Arrays and Structs
    • How to Save Loop Results in an Array in C
    • Structs in C: Grouping Related Data (with Python and R Comparisons)
  • Random Numbers
    • srand(time(NULL)) in C: Why Random Numbers Repeat and How to Seed Them
    • Tossing a Die in C Until We Get a 6

C Programming

All coursesProgrammingC
Beginner

C Programming

Learn C from Hello, World! to loops, arrays, structs and random numbers, with worked examples, practice problems and hints.

AA Created by
Abdullah Al Mahmud, Stat Mania
Last updated 10.2026

📚 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 Started2 lessons · 10 min

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.Reading5 min1.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.Reading5 min
Module 2Variables and Data Types2 lessons · 20 min

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.Reading15 min2.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.Reading5 min
Module 3Operators and Input2 lessons · 10 min

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.Reading5 min3.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.Code5 min
Module 4Making Decisions3 lessons · 30 min

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.Reading5 min4.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.Reading15 min4.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.Reading10 min
Module 5Loops6 lessons · 55 min

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.Reading5 min5.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.Reading10 min5.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.Code10 min5.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.Lab10 min5.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.Lab10 min5.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.Lab10 min
Module 6Arrays and Structs2 lessons · 15 min

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.Code5 min6.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.Reading10 min
Module 7Random Numbers2 lessons · 20 min

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.Reading10 min7.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.Code10 min
AA

Abdullah Al Mahmud

Stat Mania

Stat Mania builds free, hands-on statistics and programming courses.

0%
0 of 19 lessons
Start course
  • Modules and lessons
  • Practice problems with hints
  • Saved progress, no account
  • Works on phones

Progress is saved in this browser only.

Back to top
Stat Mania

Free, hands-on statistics and programming courses that run right in your browser.

Courses

All courses R Programming Statistics Probability

Resources

Practice quizzes Tools & games Quarto docs Course kit on GitHub

Company

Home About Contact Privacy policy Terms of use
© Stat Mania. All rights reserved.
Getting Started