C Programming free projects idea’s
This C Programming free projects idea’s page is about Learn the fundamentals of C programming, including data types, variables, control structures, and functions. Explore examples and exercises to help you get started with C. If you don’t know the basic of C programming click here.
Basic Calculator:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(void)
{
// Read the operator and operands from the standard input
char operator[4];
double operand1, operand2;
scanf("%s %lf %lf", operator, &operand1, &operand2);
// Perform the specified operation
if (strcmp(operator, "+") == 0)
{
printf("%.2f\n", operand1 + operand2);
}
else if (strcmp(operator, "-") == 0)
{
printf("%.2f\n", operand1 - operand2);
}
else if (strcmp(operator, "*") == 0)
{
printf("%.2f\n", operand1 * operand2);
}
else if (strcmp(operator, "/") == 0)
{
if (operand2 == 0)
{
printf("Error: Division by zero\n");
return 1;
}
printf("%.2f\n", operand1 / operand2);
}
else if (strcmp(operator, "^") == 0)
{
printf("%.2f\n", pow(operand1, operand2));
}
else
{
printf("Error: Invalid operator\n");
return 1;
}
return 0;
}
Text Based Game:
#include "stdio.h"
#include "stdlib.h"
#include "time.h"
#include "stddef.h"
int main(void)
{
srand(time(NULL)); // Seed the random number generator
// Introduction
printf("Welcome to the dungeon crawl!\n");
printf("You are a brave adventurer exploring a dangerous dungeon.\n");
printf("You must navigate through the dungeon, fighting monsters and finding treasure.\n");
// Main game loop
while (1)
{
// Generate a random event
int event = rand() % 3; // Generates a random number between 0 and 2
if (event == 0)
{
// Monster encounter
printf("You encounter a monster!\n");
printf("Do you want to fight or run? (f/r)\n");
char choice;
scanf(" %c", &choice);
if (choice == 'f')
{
// Generate a random outcome for the battle
int outcome = rand() % 2; // Generates a random number between 0 and 1
if (outcome == 0)
{
printf("You defeat the monster and earn some treasure!\n");
}
else
{
printf("The monster was too strong and you have been defeated.\n");
printf("Game over.\n");
break;
}
}
else if (choice == 'r')
{
// Generate a random outcome for the escape
int outcome = rand() % 2; // Generates a random number between 0 and 1
if (outcome == 0)
{
printf("You successfully escape the monster.\n");
}
else
{
printf("The monster catches up to you and you have been defeated.\n");
printf("Game over.\n");
break;
}
}
}
}
return 0;
}
Simple Salary Slip generator:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define NAME_LEN 50
struct Employee
{
char name[NAME_LEN];
int id;
int days_present;
double daily_rate;
double pf;
double travel_allowance;
double insurance;
double incentive;
};
int main(void)
{
// Read the employee data from the standard input
struct Employee employee;
printf("Enter employee name: ");
fgets(employee.name, NAME_LEN, stdin);
printf("Enter employee ID: ");
scanf("%d", &employee.id);
printf("Enter number of days present in the month: ");
scanf("%d", &employee.days_present);
// Set the employee data
employee.daily_rate = 1000;
employee.pf = 0.1;
employee.travel_allowance = 500;
employee.insurance = 0.2;
employee.incentive = 1000;
// Calculate the gross salary and deductions
double gross_salary = employee.days_present * employee.daily_rate;
double pf_deduction = gross_salary * employee.pf;
double insurance_deduction = gross_salary * employee.insurance;
double total_deductions = pf_deduction + insurance_deduction;
// Calculate the net salary
double net_salary = gross_salary + employee.travel_allowance + employee.incentive - total_deductions;
// Print the salary slip
printf("\n");
printf("Salary Slip\n");
printf("------------\n");
printf("Employee Name: %s", employee.name);
printf("Employee ID: %d\n", employee.id);
printf("Days Present: %d\n", employee.days_present);
printf("Gross Salary: $%.2f\n", gross_salary);
printf("PF Deduction: $%.2f\n", pf_deduction);
printf("Insurance Deduction: $%.2f\n", insurance_deduction);
printf("Total Deductions: $%.2f\n", total_deductions);
printf("Travel Allowance: $%.2f\n", employee.travel_allowance);
printf("Incentive: $%.2f\n", employee.incentive);
printf("Net Salary: $%.2f\n", net_salary);
return 0;
}
Output of the code:

Do subscribe on YouTube for the tutorials on C programming free projects idea’s and from more code go to my GitHub profile.