C Projects – Build Real-World Applications with C
Putting your knowledge into practice is one of the best ways to solidify your understanding of C programming. This tutorial features a variety of C projects, ranging from simple to more advanced applications, that will help you gain hands-on experience.
🔹 Project 1: Calculator
Build a simple calculator program that can perform basic arithmetic operations like addition, subtraction, multiplication, and division. This project will help you practice decision-making structures and user input handling in C.
Steps to build the Calculator:
- Define a menu to allow users to choose the operation.
- Accept input for two numbers.
- Implement functions for each arithmetic operation.
- Display the result of the operation.
#include <stdio.h> void add(float a, float b) { printf("Result: %.2f\n", a + b); } void subtract(float a, float b) { printf("Result: %.2f\n", a - b); } void multiply(float a, float b) { printf("Result: %.2f\n", a * b); } void divide(float a, float b) { if (b != 0) printf("Result: %.2f\n", a / b); else printf("Error! Division by zero.\n"); } int main() { float num1, num2; int choice; printf("Simple Calculator\n"); printf("1. Add\n2. Subtract\n3. Multiply\n4. Divide\n"); printf("Enter choice: "); scanf("%d", &choice); printf("Enter two numbers: "); scanf("%f %f", &num1, &num2); switch (choice) { case 1: add(num1, num2); break; case 2: subtract(num1, num2); break; case 3: multiply(num1, num2); break; case 4: divide(num1, num2); break; default: printf("Invalid choice.\n"); } return 0; }
🔹 Project 2: Number Guessing Game
Create a number guessing game where the program generates a random number, and the user has to guess it within a certain number of attempts. This project will improve your skills in loops, conditional statements, and random number generation.
Steps to build the Number Guessing Game:
- Generate a random number between 1 and 100.
- Prompt the user to enter guesses.
- Inform the user if their guess is too high or too low.
- Limit the number of attempts (e.g., 10 guesses).
- Display a success message if the user guesses the number correctly.
#include <stdio.h> #include <stdlib.h> #include <time.h> int main() { int guess, number, attempts = 0; // Initialize random number generator srand(time(0)); number = rand() % 100 + 1; printf("Guess the number (between 1 and 100): "); do { attempts++; scanf("%d", &guess); if (guess > number) printf("Too high! Try again: "); else if (guess < number) printf("Too low! Try again: "); else printf("Congratulations! You guessed the number in %d attempts.\n", attempts); } while (guess != number && attempts < 10); if (guess != number) printf("Sorry! You've exhausted all attempts. The correct number was %d.\n", number); return 0; }
🔹 Project 3: Student Management System
Develop a simple student management system that can store student records, including names, roll numbers, and grades. Implement functionalities such as adding new students, displaying student details, and updating records.
Steps to build the Student Management System:
- Define a structure to store student information.
- Allow the user to add student records.
- Display a list of all students.
- Allow the user to search for a student by roll number.
- Update student grades or other information.
#include <stdio.h> struct Student { int roll_no; char name[50]; float grade; }; void display(struct Student student) { printf("Roll No: %d\n", student.roll_no); printf("Name: %s\n", student.name); printf("Grade: %.2f\n", student.grade); } int main() { struct Student student; char choice; printf("Student Management System\n"); do { printf("Enter Roll No: "); scanf("%d", &student.roll_no); printf("Enter Name: "); scanf("%s", student.name); printf("Enter Grade: "); scanf("%f", &student.grade); display(student); printf("\nWould you like to add another student? (Y/N): "); getchar(); // to capture newline character after entering grade scanf("%c", &choice); } while (choice == 'Y' || choice == 'y'); return 0; }
🔹 Project 4: Bank Management System
Create a simple bank management system where users can create accounts, deposit and withdraw money, and check their balance. This project will help you work with file handling and structures in C.
Steps to build the Bank Management System:
- Define a structure to store account details.
- Allow the user to create an account with an initial balance.
- Implement deposit and withdrawal functionalities.
- Save account details to a file for persistent storage.
- Display account balance and transaction history.
#include <stdio.h> #include <stdlib.h> struct Account { int account_number; char name[50]; float balance; }; void deposit(struct Account* acc, float amount) { acc->balance += amount; printf("Deposited: %.2f\n", amount); printf("New Balance: %.2f\n", acc->balance); } void withdraw(struct Account* acc, float amount) { if (acc->balance >= amount) { acc->balance -= amount; printf("Withdrawn: %.2f\n", amount); printf("New Balance: %.2f\n", acc->balance); } else { printf("Insufficient balance!\n"); } } int main() { struct Account account; int choice; float amount; printf("Bank Management System\n"); printf("Enter Account Number: "); scanf("%d", &account.account_number); printf("Enter Name: "); scanf("%s", account.name); account.balance = 0; do { printf("\n1. Deposit\n2. Withdraw\n3. Check Balance\n4. Exit\n"); printf("Enter your choice: "); scanf("%d", &choice); switch (choice) { case 1: printf("Enter deposit amount: "); scanf("%f", &amount); deposit(&account, amount); break; case 2: printf("Enter withdrawal amount: "); scanf("%f", &amount); withdraw(&account, amount); break; case 3: printf("Account Balance: %.2f\n", account.balance); break; case 4: printf("Exiting...\n"); break; default: printf("Invalid choice!\n"); } } while (choice != 4); return 0; }
🔹 Project 5: Todo List Application
Create a console-based Todo List application where users can add, remove, and view their tasks. This project will help you practice file I/O, data storage, and list manipulation.
Steps to build the Todo List Application:
- Allow the user to add tasks.
- Allow the user to remove tasks.
- Store tasks in a file for persistence.
- Allow the user to view all tasks in the list.
#include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_TASKS 100 #define TASK_SIZE 100 void add_task(char tasks[][TASK_SIZE], int* task_count) { if (*task_count < MAX_TASKS) { printf("Enter task: "); getchar(); // To clear newline character from previous input fgets(tasks[*task_count], TASK_SIZE, stdin); (*task_count)++; } else { printf("Task list is full!\n"); } } void display_tasks(char tasks[][TASK_SIZE], int task_count) { printf("Todo List:\n"); for (int i = 0; i < task_count; i++) { printf("%d. %s", i + 1, tasks[i]); } } int main() { char tasks[MAX_TASKS][TASK_SIZE]; int task_count = 0; int choice; do { printf("\n1. Add Task\n2. View Tasks\n3. Exit\n"); printf("Enter choice: "); scanf("%d", &choice); switch (choice) { case 1: add_task(tasks, &task_count); break; case 2: display_tasks(tasks, task_count); break; case 3: printf("Exiting...\n"); break; default: printf("Invalid choice!\n"); } } while (choice != 3); return 0; }
Conclusion
These projects are a great way to practice and apply your C programming skills. Start with simple projects and gradually move on to more complex applications as you become more comfortable with the language.