C from Zero · Week 1
0% complete0 / 49 activities
Saved locally

Learn C like your first programming week actually matters.

This is built for someone who has only recently started using a laptop for real coding. Read the idea first. Run the example in a real C compiler. Record what happened. Only then unlock the explanation. Practice until you can write the next program without copying.

7chapters
49core activities
14run-first examples
20final quiz questions
01

What Programming Really Is

Why computers need formal programming languages instead of ordinary English.

Introduction

A computer is extremely good at executing precise instructions and extremely bad at guessing what a human meant. When a person says “make the screen show my name,” another person can fill in missing details from context. A compiler cannot safely do that. A programming language therefore gives us strict rules for expressing operations, values, structure and order.

When and why?

Programming is useful whenever we want a machine to perform a process consistently: calculate, store, compare, transform, search, communicate or control hardware. C is particularly useful for learning how software relates closely to memory, types and machine operations.

How source code becomes a running program

  1. You write source code in a text editor/IDE.
  2. The preprocessor handles directives such as #include.
  3. The compiler checks C syntax and semantics and translates the source.
  4. The resulting program is linked with required components and can be executed.
Key idea: English is flexible because humans resolve ambiguity. C is strict because the compiler needs a precise interpretation of every token and expression.

Example 1 — your first tiny C program

c1_example1.coutput intentionally hidden
#include <stdio.h>

int main(void)
{
    printf("Hello, C.");
    return 0;
}

Example 2 — two printf calls

c1_example2.cno output shown
#include <stdio.h>

int main(void)
{
    printf("C");
    printf(" is precise.");
    return 0;
}

Activities · Chapter 1

Mini Project 1 — About Me Terminal: Print your name, branch, college, and one sentence about why you are learning C. Use readable spacing and at least one comment.
02

Your First C Program, Line by Line

Understand #include, stdio.h, main, braces, statements, printf and return.

Introduction

Most beginner C programs look different on the surface but share a recognizable skeleton. Learning that skeleton reduces fear: you start seeing familiar parts instead of a wall of symbols.

When and why?

#include <stdio.h> gives the program access to declarations for standard input/output functions used in these lessons. main provides the normal entry point for a hosted C program. Braces group a block. A semicolon terminates many statements. These rules let the compiler parse the program unambiguously.

Do not memorize punctuation as decoration. ;, (), {} and #include each have a language-level purpose.

Example 1 — structure

c2_example1.c
#include <stdio.h>

int main(void)
{
    printf("I am learning C.");
    return 0;
}

Example 2 — comments

c2_example2.c
#include <stdio.h>

int main(void)
{
    // The next line creates visible output.
    printf("Comments are for humans.");
    return 0;
}

Activities · Chapter 2

Mini Project 2 — Terminal Intro Card: Recreate a small terminal screen using only printf, blank lines and a comment. Make it readable rather than decorative.
03

Variables & Data Types

Give information names and choose an appropriate kind of value.

Introduction

Programs need memory to keep information while they run. A variable gives a stored value a name. A type tells C what kind of value is being represented and affects how that value is stored and used.

When and why?

Use variables whenever a value needs to be remembered, reused, changed, compared or included in a calculation. Choosing a type is part of designing the program: an age is normally a whole number, a price may require a decimal representation, and a single initial is a character.

  • int → whole numbers
  • float → floating-point values
  • double → higher-precision floating-point values
  • char → one character
Important distinction: x = 5 assigns 5 to x. x == 5 asks whether x is equal to 5. You will use this distinction constantly.

Example 1 — several types

c3_example1.c
#include <stdio.h>

int main(void)
{
    int age = 20;
    float height = 5.8f;
    char grade = 'A';

    printf("%d\\n", age);
    printf("%.1f\\n", height);
    printf("%c\\n", grade);
    return 0;
}

Example 2 — assignment changes the stored value

c3_example2.c
#include <stdio.h>

int main(void)
{
    int score = 10;
    score = 25;
    printf("%d", score);
    return 0;
}

Activities · Chapter 3

Mini Project 3 — Student Profile: Store a student's age, one decimal value, a grade character and a year as variables. Print each with a useful label.
04

Input with scanf()

Let the person running your program supply values at runtime.

Introduction

A fixed program always uses the values you typed into its source code. An interactive program can ask for information while it is running. scanf() is a standard input function used in basic C programs to read formatted values.

When and why?

Use input when values are not known until runtime: age, marks, quantity, distance, temperature and so on. The program becomes a reusable procedure instead of a single calculation with hard-coded values.

Why the &?

For an ordinary integer variable, scanf needs the variable's memory address so it knows where to store the value. The & operator obtains that address. You will learn pointers properly later; for now understand the reason, not just the pattern.

Common mistake: for int age;, the ordinary beginner form is scanf("%d", &age);, not scanf("%d", age);.

Example 1 — one input

c4_example1.c
#include <stdio.h>

int main(void)
{
    int age;
    printf("Enter your age: ");
    scanf("%d", &age);
    printf("You entered %d", age);
    return 0;
}

Example 2 — two inputs

c4_example2.c
#include <stdio.h>

int main(void)
{
    int a, b;
    scanf("%d %d", &a, &b);
    printf("First = %d\\nSecond = %d", a, b);
    return 0;
}

Activities · Chapter 4

Mini Project 4 — Two-Number Calculator: Input two integers and print their sum, difference, product and quotient. Test it with positive, zero and negative values.
05

Operators & Expressions

Make values calculate, compare and form useful conditions.

Introduction

An expression combines values, variables and operators to produce a value. C provides arithmetic operators such as +, -, *, / and %, plus comparison and logical operators used for decisions.

Why integer division matters

When both operands are integers, division uses integer arithmetic. Therefore 17 / 5 produces 3, while 17 % 5 produces 2. This is not a bug; it is the defined operation for integer operands.

Comparison & logic

>, <, >=, <=, == and != compare values. && means AND, || means OR, and ! means NOT.

Example 1 — quotient and remainder

c5_example1.c
#include <stdio.h>

int main(void)
{
    printf("%d\\n", 17 / 5);
    printf("%d\\n", 17 % 5);
    return 0;
}

Example 2 — comparisons become 1 or 0

c5_example2.c
#include <stdio.h>

int main(void)
{
    int a = 10;
    printf("%d\\n", a > 5);
    printf("%d\\n", a == 10);
    printf("%d\\n", a != 10);
    return 0;
}

Activities · Chapter 5

Mini Project 5 — Shopping Math: Input item price and quantity. Calculate subtotal and add one extra calculation such as a percentage discount.
06

Decisions with if / else

Teach the program to choose a path based on a condition.

Introduction

Most useful programs make decisions. A result may be pass or fail; a number may be positive, negative or zero; a purchase may qualify for a discount. if, else if and else let a program choose between these paths.

When and why?

Start with the decision in plain language: “if the number is divisible by 2, it is even.” Only after that translate the condition into C. This prevents syntax from becoming a substitute for reasoning.

Example 1 — even / odd

c6_example1.c
#include <stdio.h>

int main(void)
{
    int n = 14;

    if (n % 2 == 0)
        printf("Even");
    else
        printf("Odd");

    return 0;
}

Example 2 — multiple branches

c6_example2.c
#include <stdio.h>

int main(void)
{
    int marks = 78;

    if (marks >= 90)
        printf("A");
    else if (marks >= 75)
        printf("B");
    else if (marks >= 40)
        printf("C");
    else
        printf("F");

    return 0;
}

Activities · Chapter 6

Mini Project 6 — Result Checker: Input three subject marks, calculate the average, then display a grade using multiple conditions. Test boundary values such as 40, 75 and 90.
07

Problem Solving Before Code

Learn a repeatable method for turning a problem into a program.

Introduction

Beginners often ask, “Which C statement should I use?” A better question is, “What exact steps solve this problem?” Syntax comes after the idea. Your workflow should be: understand → identify inputs and outputs → write the mathematics/logic → make an algorithm → code → test → debug.

Worked example — larger of two numbers

  1. Read a and b.
  2. Compare them using a > b.
  3. If true, the larger value is a.
  4. Otherwise the larger value is b (including equality).

Example — run it before reading the explanation

c7_example.c
#include <stdio.h>

int main(void)
{
    int a, b;
    printf("Enter two numbers: ");
    scanf("%d %d", &a, &b);

    if (a > b)
        printf("Larger = %d", a);
    else
        printf("Larger = %d", b);

    return 0;
}

Activities · Chapter 7

Final Week 1 Project — Personal Utility Console: Build one C program with a simple menu: add two numbers, check even/odd, calculate rectangle area, and compare two numbers. Before coding, write each mini-problem's inputs, outputs and steps.
Q

Long Final Quiz

Concepts + code reading + actual output prediction.

Do the output questions without compiling first. You are training your ability to read code, not only your ability to run it.