🔴 Advanced  ·  Lesson 47

50 Important C Programs

Why practice programs?

You cannot learn to swim by reading about water, and you cannot learn C without writing programs. This is a curated list of 50 important C programs grouped by topic, with several fully worked examples. Try each one yourself first, then check your logic.

Every program here uses only the basics covered elsewhere on the site, so each links naturally to a lesson when you want more depth.

Number programs

  1. Check even or odd
  2. Check prime number
  3. Factorial of a number
  4. Fibonacci series
  5. Reverse a number
  6. Sum of digits
  7. Check palindrome number
  8. Check Armstrong number
  9. Largest of three numbers
  10. Multiplication table
  11. Convert decimal to binary
  12. GCD and LCM of two numbers

Pattern programs

  1. Right-angled star triangle
  2. Inverted star triangle
  3. Pyramid of stars
  4. Number triangle (1, 12, 123...)
  5. Floyd's triangle
  6. Pascal's triangle
  7. Diamond pattern
  8. Hollow square pattern

Array and string programs

  1. Largest and smallest in an array
  2. Sum and average of an array
  3. Reverse an array
  4. Sort an array (bubble/selection/insertion)
  5. Search an element (linear/binary)
  6. Matrix multiplication
  7. Transpose of a matrix
  8. String length without strlen
  9. Reverse a string
  10. Check string palindrome
  11. Count vowels and consonants
  12. Convert case (upper/lower)

...and more covering linked lists, stacks, queues, file handling and small mini projects — 50 in total.

Example: prime number

C Language
#include <stdio.h>
int main() {
    int n, isPrime = 1;
    printf("Enter a number: ");
    scanf("%d", &n);
    if (n < 2) isPrime = 0;
    for (int i = 2; i * i <= n; i++)
        if (n % i == 0) { isPrime = 0; break; }
    printf(isPrime ? "Prime\n" : "Not prime\n");
    return 0;
}
Run: Enter a number: 13
Output:
Prime

Example: reverse a number

C Language
#include <stdio.h>
int main() {
    int n, rev = 0;
    scanf("%d", &n);
    while (n != 0) {
        rev = rev * 10 + n % 10;   // pull off last digit
        n /= 10;
    }
    printf("Reversed: %d\n", rev);
    return 0;
}
Run: 1234
Output:
Reversed: 4321

The trick rev * 10 + n % 10 peels the last digit off n and appends it to rev each loop.

Example: a star pattern

C Language
#include <stdio.h>
int main() {
    int rows = 4;
    for (int i = 1; i <= rows; i++) {
        for (int j = 1; j <= i; j++)
            printf("* ");
        printf("\n");
    }
    return 0;
}
Output:
*
* *
* * *
* * * *

The outer loop picks the row; the inner loop prints as many stars as the row number. Almost every pattern is a variation of this nested-loop idea.

How to practise well

  • Write first, look later — attempt each program before reading any solution.
  • Trace by hand — run a small input on paper to see the logic.
  • Fix your own bugs — the errors you solve yourself stick best.
  • Vary it — change a program slightly (descending pattern, different range) to test understanding.
🏋️ Challenge

Pick five programs from the lists above you have not written yet and code them today from a blank editor. Then modify each one slightly so it does something a little different.

Summary

  • Practice is the only way to get fluent in C — reading is not enough.
  • The 50 programs span numbers, patterns, arrays, strings and small projects.
  • Classic programs (prime, reverse, palindrome, patterns) also appear in interviews.
  • Always try writing a program yourself before checking a solution.
  • Trace by hand and modify programs to deepen understanding.

Frequently Asked Questions

What are the best C programs to practise for beginners?
Great starter programs include checking whether a number is even, odd or prime, reversing a number, finding a factorial, printing star and number patterns, finding the largest element in an array, and reversing a string. These cover loops, conditions, arrays and functions — the core skills.
How many C programs should I practise?
There is no fixed number, but working carefully through around fifty varied programs — a mix of number, pattern, array and string problems — gives most beginners solid confidence. Understanding each one fully matters far more than rushing through a long list.
Are C practice programs useful for interviews?
Yes. Classic programs such as prime check, palindrome, reversing a number or string, and sorting appear constantly in interviews and viva exams. Being able to write them from memory and explain the logic is exactly what interviewers look for.
How do I get better at writing C programs?
Practise actively: read a problem, try to write the code yourself before looking at any solution, run it, and fix your own mistakes. Tracing the program by hand with a small input builds the deep understanding that simply copying code cannot.
What topics do C practice programs usually cover?
They typically span numbers (even/odd, prime, factorial, Fibonacci), patterns (stars, numbers, pyramids), arrays (largest, sum, sorting, searching), strings (length, reverse, palindrome), and simple menu-driven projects, giving all-round practice of the language basics.
← Back to C Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

💻 Live Code Editor

This page's programs are ready here — run them, edit them, and learn. No installation needed.
Powered by OneCompiler. The code loads into the editor automatically — press Run to see the output. If the editor does not open, open it in a new tab.