20 C Programs for Beginners

    Atul Kabra3 min readUpdated

    The fastest way to learn C is to write small programs by hand. Below are 20 beginner C programs worth practising, grouped by the concept they reinforce. Each builds on the basics — variables, operators, if-else, and loops — so work through them in order.

    The 20 programs

    Basics & operators

    1. Print "Hello, World!".
    2. Add two numbers entered by the user.
    3. Swap two numbers (with and without a third variable).
    4. Find the area of a circle given the radius.
    5. Convert temperature from Celsius to Fahrenheit.

    Decision making 6. Check whether a number is even or odd. 7. Find the largest of three numbers. 8. Check whether a year is a leap year. 9. Compute a grade from marks using an if-else ladder. 10. Check whether a character is a vowel or consonant.

    Loops 11. Print the multiplication table of a number. 12. Sum the first N natural numbers. 13. Count the digits in a number. 14. Reverse a number (e.g. 123 → 321). 15. Check whether a number is a palindrome.

    Logic & patterns 16. Check whether a number is prime. 17. Print the factorial of a number. 18. Generate the Fibonacci series up to N terms. 19. Print a right-angled triangle of stars. 20. Find the greatest common divisor (GCD) of two numbers.

    A worked example: even or odd

    Here is program 6 written out, fully commented, so you can see the structure you'll reuse for the rest:

    #include <stdio.h>
    
    int main(void) {
        int number;
    
        printf("Enter an integer: ");
        if (scanf("%d", &number) != 1) {   /* check the read succeeded */
            printf("Invalid input.\n");
            return 1;
        }
    
        /* The remainder when divided by 2 tells us even or odd */
        if (number % 2 == 0) {
            printf("%d is even.\n", number);
        } else {
            printf("%d is odd.\n", number);
        }
    
        return 0;
    }
    

    The % (modulo) operator gives the remainder; if dividing by 2 leaves nothing, the number is even.

    Want to learn this properly?

    Join the waitlist for C Programming — beginner-friendly, project-first classes in Jalgaon.

    Explore C Programming

    How to practise effectively

    • Type, don't copy. Writing each line by hand builds memory.
    • Predict the output first, then run it and compare. Mismatches are where learning happens.
    • Start tiny, then extend. Got even/odd working? Now count how many even numbers are in a range.
    • Trace by hand for loop-heavy programs (11–20): write each variable's value pass by pass.
    • Compile with warnings on (e.g. -Wall) so the compiler points out mistakes early.

    Suggested order

    Do 1–5 to get comfortable with input, output, and arithmetic. Move to 6–10 once if-else makes sense. Tackle 11–15 after loops, and finish with 16–20, which combine everything. Programs 16–18 (prime, factorial, Fibonacci) are also great practice for functions and recursion.

    Common mistakes while practising

    • Forgetting & in scanfscanf("%d", number) should be &number.
    • = instead of == inside conditions.
    • Off-by-one loop bounds in pattern and series programs.
    • Not checking scanf's return value, letting bad input run wild.
    • Integer overflow in factorial/Fibonacci for large inputs — use long long.

    FAQ

    Which program should I start with? Number 1, then 2 and 6 — they cover output, input, and a decision in the fewest lines.

    Do I need an IDE? Any editor plus a compiler (like GCC) works. Keep it simple while learning.

    Continue at the hub C Programming, then If-Else in C and For Loops in C.

    Want to learn this properly? Join the waitlist for our C Programming course — taught in Jalgaon.

    Want to learn this properly?

    Join the waitlist for C Programming — beginner-friendly, project-first classes in Jalgaon.

    Explore C Programming
    Atul Kabra

    Founder, Infoplanet

    Atul Kabra founded Infoplanet in 2001 and has spent over two decades teaching programming — C, C++, Java, databases and more — to students across Maharashtra.

    Related guides