0% found this document useful (0 votes)
33 views

C Language Mini Projects

Uploaded by

RAKSHITH REDDY
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

C Language Mini Projects

Uploaded by

RAKSHITH REDDY
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

C Language Mini Projects

i need to do some mini projects using c language for ece


students

Here are some mini-project ideas using the C language that are suitable for ECE students:

1. Digital Calculator
Description: Create a digital calculator that can perform basic arithmetic operations like
addition, subtraction, multiplication, and division.

Skills Involved: Basic programming in C, handling user input, and using arithmetic
operations.

2. Traffic Light Simulation


Description: Develop a program to simulate the operation of a traffic light. The
simulation should cycle through red, yellow, and green lights with appropriate delays.

Skills Involved: Loops, conditional statements, and timers.

3. Temperature Conversion System


Description: Write a program that converts temperature between Celsius, Fahrenheit,
and Kelvin.

Skills Involved: Mathematical calculations and conditional logic.

4. Electronic Voting Machine Simulation


Description: Create a simple electronic voting machine program where users can cast
their votes, and the program displays the result at the end.

Skills Involved: Arrays, user input, and control structures.

5. Basic Home Automation System


Description: Design a menu-based system to control basic home appliances like lights,
fans, and AC using on/off commands.

Skills Involved: Functions, user-defined data types, and control statements.

6. Digital Clock

1/15
Description: Create a program to display the current time in HH:MM:SS format, updating
every second.

Skills Involved: Looping structures and handling time delays.

7. Number Guessing Game


Description: Implement a number guessing game where the program randomly
generates a number, and the player has to guess it within a limited number of attempts.

Skills Involved: Random number generation, loops, and conditional statements.

8. Capacitor Value Calculator


Description: Write a program that takes the color code of a capacitor as input and
calculates its value.

Skills Involved: Arrays, strings, and conditional logic.

9. Serial Communication Simulation


Description: Simulate serial communication between two devices using C language to
transfer data in the form of strings.

Skills Involved: String manipulation and data handling.

10. Matrix Multiplication Program


Description: Create a program to perform matrix multiplication of two matrices input by
the user.

Skills Involved: Multidimensional arrays and nested loops.

These projects cover different aspects of the C programming language and can help ECE
students develop their coding skills while understanding how software interacts with
hardware. Let me know if you need more details about any of these projects!

which among these is best

The best mini-project among these depends on the level of knowledge and interests of the
students. However, for ECE students, I recommend the Traffic Light Simulation as the most
suitable mini-project for several reasons:

Why Traffic Light Simulation is Ideal:

2/15
1. Relevance to ECE: This project closely aligns with the concepts of digital electronics and
embedded systems, which are core topics in the Electronics and Communication
Engineering (ECE) curriculum.

2. Simple but Effective: It involves using fundamental programming concepts like loops,
conditional statements, and timing, making it an excellent choice for beginners.

3. Real-World Application: The traffic light system is a practical example that helps
students understand how programming can be used in embedded systems to control
hardware in real-time.

4. Scalable: The project can be expanded to include additional functionalities like


pedestrian crossings, traffic density monitoring, or even synchronization with other
traffic signals for more advanced students.

Overall, the Traffic Light Simulation provides a good balance between complexity and
learning value, making it an excellent project for ECE students to gain hands-on experience
with programming and real-world applications.

ok
generate me code for every project with detailed
explanation

Here's the code for each mini-project with detailed explanations. Let's go through them one
by one.

1. Digital Calculator

Code:

#include <stdio.h>

int main() {
char operator;
double num1, num2, result;

// Asking the user to enter the operator


printf("Enter an operator (+, -, *, /): ");
scanf("%c", &operator);

// Asking the user to enter two numbers

3/15
printf("Enter two numbers: ");
scanf("%lf %lf", &num1, &num2);

// Switch statement to perform the desired operation


switch (operator) {
case '+':
result = num1 + num2;
break;
case '-':
result = num1 - num2;
break;
case '*':
result = num1 * num2;
break;
case '/':
if (num2 != 0) {
result = num1 / num2;
} else {
printf("Error! Division by zero.\n");
return 1; // Exit the program
}
break;
default:
printf("Invalid operator\n");
return 1; // Exit the program
}

// Displaying the result of the operation


printf("Result: %.2lf\n", result);
return 0;
}

Explanation:

The user inputs an operator ( + , - , * , / ) and two numbers.

The program uses a switch statement to perform the operation based on the user's
input.

If the user tries to divide by zero, the program displays an error message.

2. Traffic Light Simulation

4/15
Code:

#include <stdio.h>
#include <unistd.h> // For sleep function

int main() {
while (1) { // Infinite loop to keep the simulation running
printf("RED Light - STOP\n");
sleep(5); // Wait for 5 seconds

printf("YELLOW Light - GET READY\n");


sleep(2); // Wait for 2 seconds

printf("GREEN Light - GO\n");


sleep(5); // Wait for 5 seconds
}
return 0;
}

Explanation:

The program runs an infinite loop simulating the cycling of a traffic light.

The sleep function is used to create delays to mimic the time for each light.

The lights change from RED to YELLOW to GREEN continuously.

3. Temperature Conversion System

Code:

#include <stdio.h>

int main() {
int choice;
float temperature, converted;

// Displaying conversion options


printf("Temperature Conversion:\n");
printf("1. Celsius to Fahrenheit\n");
printf("2. Fahrenheit to Celsius\n");

5/15
printf("Enter your choice (1 or 2): ");
scanf("%d", &choice);

// Asking user to enter temperature value


if (choice == 1) {
printf("Enter temperature in Celsius: ");
scanf("%f", &temperature);
converted = (temperature * 9/5) + 32; // Celsius to Fahrenheit formula
printf("Temperature in Fahrenheit: %.2f°F\n", converted);
} else if (choice == 2) {
printf("Enter temperature in Fahrenheit: ");
scanf("%f", &temperature);
converted = (temperature - 32) * 5/9; // Fahrenheit to Celsius formula
printf("Temperature in Celsius: %.2f°C\n", converted);
} else {
printf("Invalid choice\n");
}

return 0;
}

Explanation:

The program offers two conversion options: Celsius to Fahrenheit and Fahrenheit to
Celsius.

The conversion is performed based on the user's choice, using standard formulas.

4. Electronic Voting Machine Simulation

Code:

#include <stdio.h>

int main() {
int vote, candidate1 = 0, candidate2 = 0, candidate3 = 0, choice;

do {
// Displaying candidates to vote for
printf("1. Vote for Candidate 1\n");
printf("2. Vote for Candidate 2\n");

6/15
printf("3. Vote for Candidate 3\n");
printf("Enter your vote (1-3): ");
scanf("%d", &vote);

// Tally the votes based on user input


switch (vote) {
case 1: candidate1++; break;
case 2: candidate2++; break;
case 3: candidate3++; break;
default: printf("Invalid vote\n"); break;
}

// Asking the user if they want to continue voting


printf("Do you want to vote again? (1 for Yes / 0 for No): ");
scanf("%d", &choice);
} while (choice == 1);

// Displaying the voting results


printf("Voting Results:\n");
printf("Candidate 1: %d votes\n", candidate1);
printf("Candidate 2: %d votes\n", candidate2);
printf("Candidate 3: %d votes\n", candidate3);

return 0;
}

Explanation:

Users vote for one of three candidates.

The program counts the votes and displays the results when voting is complete.

5. Basic Home Automation System

Code:

#include <stdio.h>

int main() {
int choice;
int light = 0, fan = 0, ac = 0; // Device states (0: off, 1: on)

7/15
while (1) {
// Displaying menu options for the user
printf("1. Toggle Light\n");
printf("2. Toggle Fan\n");
printf("3. Toggle AC\n");
printf("4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);

// Controlling the devices based on the user choice


switch (choice) {
case 1: light = !light; printf("Light is now %s\n", light ? "ON" :
"OFF"); break;
case 2: fan = !fan; printf("Fan is now %s\n", fan ? "ON" : "OFF");
break;
case 3: ac = !ac; printf("AC is now %s\n", ac ? "ON" : "OFF"); break;
case 4: return 0; // Exit the program
default: printf("Invalid choice\n"); break;
}
}
return 0;
}

Explanation:

Users can toggle the state of three devices: Light, Fan, and AC.

The program continuously runs until the user decides to exit.

I will provide the codes for the remaining projects in the next response to keep the
information organized. Let me know if you have any questions or if you want more details on
these projects!

continue

Here’s the continuation of the mini-project codes with detailed explanations.

6. Digital Clock

Code:

8/15
#include <stdio.h>
#include <time.h>
#include <unistd.h> // For sleep function

int main() {
int hours, minutes, seconds;

while (1) { // Infinite loop to keep the clock running


// Get the current time
time_t now = time(NULL);
struct tm *local = localtime(&now);

hours = local->tm_hour;
minutes = local->tm_min;
seconds = local->tm_sec;

// Clear the console


printf("\r%02d:%02d:%02d", hours, minutes, seconds);
fflush(stdout); // Flush output buffer to update display

sleep(1); // Wait for 1 second


}

return 0;
}

Explanation:

This program retrieves the current system time using the time function and the tm
structure.

It continuously updates the display every second to show the current time in HH:MM:SS
format.

The \r in the printf function ensures that the time is updated on the same line in the
console.

7. Number Guessing Game

Code:

9/15
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main() {
int number, guess, attempts = 0;

// Seed the random number generator


srand(time(0));
number = rand() % 100 + 1; // Random number between 1 and 100

printf("Guess the number (1-100): ");

do {
scanf("%d", &guess);
attempts++;

if (guess > number) {


printf("Too high! Try again: ");
} else if (guess < number) {
printf("Too low! Try again: ");
} else {
printf("Congratulations! You've guessed the number %d in %d
attempts.\n", number, attempts);
}
} while (guess != number);

return 0;
}

Explanation:

The program generates a random number between 1 and 100.

The user is prompted to guess the number, and the program provides feedback on
whether the guess is too high or too low.

The game continues until the user guesses the correct number, and the total number of
attempts is displayed.

8. Capacitor Value Calculator

Code:

10/15
c

#include <stdio.h>

int main() {
char color[10];
int first_digit, second_digit, multiplier;

// Asking the user for color codes


printf("Enter the color code (e.g., Brown Red Orange): ");
scanf("%s %s %s", color, color + 1, color + 2);

// Decoding color values


if (color[0] == 'B') first_digit = 1; // Brown
else if (color[0] == 'R') first_digit = 2; // Red
else if (color[0] == 'O') first_digit = 3; // Orange
else first_digit = 0;

if (color[1] == 'B') second_digit = 1; // Brown


else if (color[1] == 'R') second_digit = 2; // Red
else if (color[1] == 'O') second_digit = 3; // Orange
else second_digit = 0;

if (color[2] == 'B') multiplier = 1; // Brown


else if (color[2] == 'R') multiplier = 10; // Red
else if (color[2] == 'O') multiplier = 100; // Orange
else multiplier = 1;

// Calculating capacitor value


int capacitor_value = (first_digit * 10 + second_digit) * multiplier;
printf("Capacitor Value: %d µF\n", capacitor_value);

return 0;
}

Explanation:

The program takes the color code of a capacitor as input (assumed to be single letters
for simplicity).

It uses simple logic to decode the color into corresponding digit values and a multiplier.

Finally, it calculates and displays the capacitor value in microfarads (µF).

11/15
9. Serial Communication Simulation

Code:

#include <stdio.h>

void sendData(char data) {


printf("Sending data: %c\n", data);
}

char receiveData() {
char data;
printf("Enter data to receive: ");
scanf(" %c", &data); // Note the space before %c to consume any leading
whitespace
return data;
}

int main() {
char data;
while (1) {
// Simulating sending data
printf("Enter data to send (or 'q' to quit): ");
scanf(" %c", &data); // Space to ignore any leading whitespace
if (data == 'q') break; // Exit condition

sendData(data); // Sending data

// Simulating receiving data


char received = receiveData();
printf("Received data: %c\n", received);
}
return 0;
}

Explanation:

The program simulates a simple serial communication system where data can be sent
and received.

The user can enter a character to send, and it prompts for a character to receive.

12/15
The loop continues until the user enters 'q' to quit.

10. Matrix Multiplication Program

Code:

#include <stdio.h>

#define MAX 10 // Maximum matrix size

int main() {
int a[MAX][MAX], b[MAX][MAX], result[MAX][MAX];
int r1, c1, r2, c2, i, j, k;

// Getting dimensions for first matrix


printf("Enter rows and columns for first matrix: ");
scanf("%d %d", &r1, &c1);

// Getting elements of the first matrix


printf("Enter elements of first matrix:\n");
for (i = 0; i < r1; i++) {
for (j = 0; j < c1; j++) {
scanf("%d", &a[i][j]);
}
}

// Getting dimensions for second matrix


printf("Enter rows and columns for second matrix: ");
scanf("%d %d", &r2, &c2);

// Checking if multiplication is possible


if (c1 != r2) {
printf("Matrix multiplication not possible.\n");
return 1; // Exit the program
}

// Getting elements of the second matrix


printf("Enter elements of second matrix:\n");
for (i = 0; i < r2; i++) {
for (j = 0; j < c2; j++) {
scanf("%d", &b[i][j]);

13/15
}
}

// Initializing the result matrix


for (i = 0; i < r1; i++) {
for (j = 0; j < c2; j++) {
result[i][j] = 0;
}
}

// Performing matrix multiplication


for (i = 0; i < r1; i++) {
for (j = 0; j < c2; j++) {
for (k = 0; k < c1; k++) {
result[i][j] += a[i][k] * b[k][j];
}
}
}

// Displaying the result


printf("Resultant Matrix:\n");
for (i = 0; i < r1; i++) {
for (j = 0; j < c2; j++) {
printf("%d ", result[i][j]);
}
printf("\n");
}

return 0;
}

Explanation:

The program accepts two matrices from the user and checks if they can be multiplied
(the number of columns of the first must equal the number of rows of the second).

It then performs the multiplication and displays the resulting matrix.

14/15
These mini-projects provide a range of practical applications for C programming, allowing
ECE students to enhance their skills in various domains. If you need any further clarification
or additional projects, feel free to ask!

15/15

You might also like