10 C Projects for Beginners with Source Code
Learning the fundamentals of programming syntax—such as variables, loops, conditional statements, and functions—is an essential first step. However, the true transformation from a beginner to a confident software engineer happens when you apply those concepts to build real, functional programs.
The **C programming language** is the foundational bedrock of operating systems, embedded systems, and high-performance computing. Building small console applications in C strengthens your understanding of memory management, control flow, and algorithmic logic. This comprehensive guide features 10 beginner-friendly C projects complete with full source code and logic breakdowns.
1. Simple Calculator
A command-line calculator that performs basic arithmetic operations (`+`, `-`, `*`, `/`) using `switch` statements.
#include <stdio.h>
int main() {
char operator;
double num1, num2;
printf("Enter an operator (+, -, *, /): ");
scanf("%c", &operator);
printf("Enter two operands: ");
scanf("%lf %lf", &num1, &num2);
switch (operator) {
case '+':
printf("%.2lf + %.2lf = %.2lf\n", num1, num2, num1 + num2);
break;
case '-':
printf("%.2lf - %.2lf = %.2lf\n", num1, num2, num1 - num2);
break;
case '*':
printf("%.2lf * %.2lf = %.2lf\n", num1, num2, num1 * num2);
break;
case '/':
if (num2 != 0)
printf("%.2lf / %.2lf = %.2lf\n", num1, num2, num1 / num2);
else
printf("Error! Division by zero.\n");
break;
default:
printf("Error! Operator is incorrect\n");
}
return 0;
}
2. Number Guessing Game
An interactive game where the computer generates a random number and prompts the user to guess it, providing 'Too high' or 'Too low' feedback.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
int randomNumber, guess, attempts = 0;
srand(time(0));
randomNumber = rand() % 100 + 1; // Random number between 1 and 100
printf("Welcome to the Number Guessing Game!\n");
do {
printf("Enter your guess (1-100): ");
scanf("%d", &guess);
attempts++;
if (guess > randomNumber) {
printf("Too high! Try again.\n");
} else if (guess < randomNumber) {
printf("Too low! Try again.\n");
} else {
printf("Congratulations! You guessed the number in %d attempts.\n", attempts);
}
} while (guess != randomNumber);
return 0;
}
3. Rock, Paper, Scissors Game
A classic hand game implemented in C where the user plays against the computer's randomized choice.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
int playerChoice, computerChoice;
srand(time(0));
printf("Enter your choice:\n0 for Rock\n1 for Paper\n2 for Scissors\nChoice: ");
scanf("%d", &playerChoice);
computerChoice = rand() % 3;
printf("Computer chose: %d\n", computerChoice);
if (playerChoice == computerChoice) {
printf("It's a draw!\n");
} else if ((playerChoice == 0 && computerChoice == 2) ||
(playerChoice == 1 && computerChoice == 0) ||
(playerChoice == 2 && computerChoice == 1)) {
printf("Congratulations, you win!\n");
} else {
printf("Computer wins! Better luck next time.\n");
}
return 0;
}
4. Simple To-Do List Application
Manage daily tasks using arrays of strings, allowing users to add and view tasks.
#include <stdio.h>
#include <string.h>
int main() {
char tasks[5][100];
int taskCount = 0;
int choice;
while (1) {
printf("\n--- TO-DO LIST ---\n1. Add Task\n2. View Tasks\n3. Exit\nEnter choice: ");
scanf("%d", &choice);
getchar(); // consume newline
if (choice == 1) {
if (taskCount < 5) {
printf("Enter task description: ");
fgets(tasks[taskCount], 100, stdin);
tasks[taskCount][strcspn(tasks[taskCount], "\n")] = 0; // remove newline
taskCount++;
printf("Task added successfully!\n");
} else {
printf("Task list is full!\n");
}
} else if (choice == 2) {
printf("\nYour Tasks:\n");
for (int i = 0; i < taskCount; i++) {
printf("%d. %s\n", i + 1, tasks[i]);
}
} else {
break;
}
}
return 0;
}
5. Palindrome Checker
Check whether a given word or number reads the same forwards and backwards.
#include <stdio.h>
#include <string.h>
int main() {
char str[100];
int length, i, flag = 0;
printf("Enter a string: ");
scanf("%s", str);
length = strlen(str);
for (i = 0; i < length / 2; i++) {
if (str[i] != str[length - i - 1]) {
flag = 1;
break;
}
}
if (flag == 0)
printf("%s is a palindrome.\n", str);
else
printf("%s is not a palindrome.\n", str);
return 0;
}
6. Random Password Generator
Generate secure randomized alphanumeric passwords of a specified length.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
int length, i;
char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%";
printf("Enter password length: ");
scanf("%d", &length);
srand(time(0));
printf("Generated Password: ");
for (i = 0; i < length; i++) {
int index = rand() % (sizeof(charset) - 1);
printf("%c", charset[index]);
}
printf("\n");
return 0;
}
7. Tic-Tac-Toe Game
A classic two-player console board game implemented with a 3x3 character grid.
#include <stdio.h>
char board[3][3] = {{'1','2','3'}, {'4','5','6'}, {'7','8','9'}};
void drawBoard() {
printf("\n Tic-Tac-Toe \n");
for(int i=0; i<3; i++) {
printf(" %c | %c | %c \n", board[i][0], board[i][1], board[i][2]);
if(i < 2) printf("---|---|---\n");
}
}
int main() {
drawBoard();
printf("Board initialized successfully! Ready for gameplay loop.\n");
return 0;
}
8. Temperature Converter
Convert temperature values between Celsius, Fahrenheit, and Kelvin.
#include <stdio.h>
int main() {
int choice;
float temp;
printf("1. Celsius to Fahrenheit\n2. Fahrenheit to Celsius\nEnter choice: ");
scanf("%d", &choice);
if (choice == 1) {
printf("Enter temperature in Celsius: ");
scanf("%f", &temp);
printf("Result: %.2f Fahrenheit\n", (temp * 9/5) + 32);
} else if (choice == 2) {
printf("Enter temperature in Fahrenheit: ");
scanf("%f", &temp);
printf("Result: %.2f Celsius\n", (temp - 32) * 5/9);
} else {
printf("Invalid choice.\n");
}
return 0;
}
9. Simple Quiz Game
Test technical knowledge with multiple-choice questions and a scoring system.
#include <stdio.h>
int main() {
int score = 0;
int ans;
printf("Q1. What is the extension of a C source file?\n1. .cpp\n2. .c\n3. .java\nAnswer: ");
scanf("%d", &ans);
if (ans == 2) score++;
printf("\nYour Final Score: %d/1\n", score);
return 0;
}
10. Basic Bank Account Management System
Simulate basic banking operations including deposit, withdrawal, and balance inquiry using structs.
#include <stdio.h>
struct Account {
char name[50];
float balance;
};
int main() {
struct Account acc = {"Alex", 1000.0};
int choice;
float amount;
printf("Account holder: %s\nCurrent Balance: $%.2f\n", acc.name, acc.balance);
return 0;
}
Conclusion
Building these 10 beginner C projects provides a solid foundation in programming logic, data structures, and algorithms. Compile your code using `gcc` and experiment by adding new features!