Calculator

A beginner-friendly C project where you’ll learn to build a Calculator using switch and functions. Covers input handling, operator-based execution, and error fixing - everything explained clearly in Bangla. First example code without while #include <stdio.h> /// Function prototypes float add(float a, float b); float subtract(float a, float b); float multiply(float a, float b); float divide(float a, float b); int main() { float a, b, result; char op; printf("Enter a:"); scanf("%f",&a); printf("Enter b:"); scanf("%f",&b); printf("Choose operation(+, -, *, /):"); scanf(" %c", &op); switch (op) { case '+': result = add(a, b); break; case '-': result = subtract(a,b); break; case '*': result = multiply(a,b); break; case '/': result = divide(a,b); break; } printf("%.2f %c %.2f = %.2f\n", a, op, b, result); return 0; } float add(float a, float b){ return a + b; } float subtract(float a, float b){ return a - b; } float multiply(float a, float b){ return a * b; } float divide(float a, float b){ return a /b; } Validate number(float) if(scanf("%f",&a) != 1){ printf("Invalid input\n"); return 0; } validate operator if (op != '+' && op != '-' && op != '*' && op != '/'){ printf("Invalid operation\n"); return 0; } Final code #include <stdio.h> // Function prototypes float add(float a, float b); float subtract(float a, float b); float multiply(float a, float b); float divide(float a, float b); int main() { float num1, num2, result; char op; while (1) { // Input numbers printf("Enter first number: "); scanf("%f", &num1); printf("Enter second number: "); scanf("%f", &num2); // Display menu printf("\nChoose operation (+, -, *, /, = to exit): "); scanf(" %c", &op); // space before %c to skip whitespace if (op == 'q') { printf("Exiting program.\n"); break; } switch (op) { case '+': result = add(num1, num2); printf("Result: %.2f\n", result); break; case '-': result = subtract(num1, num2); printf("Result: %.2f\n", result); break; case '*': result = multiply(num1, num2); printf("Result: %.2f\n", result); break; case '/': if (num2 != 0) { result = divide(num1, num2); printf("Result: %.2f\n", result); } else { printf("Error: Division by zero!\n"); } break; default: printf("Invalid operation! Try again.\n"); } printf("\n"); // Extra line before next iteration } return 0; } // Function definitions float add(float a, float b) { return a + b; } float subtract(float a, float b) { return a - b; } float multiply(float a, float b) { return a * b; } float divide(float a, float b) { return a / b; }

Number Guessing Game in C

How random works? #include <stdlib.h> int r = rand(); Generates a pseudo-random number between 0 and RAND_MAX. Without seeding, the sequence is the same every run. 🌱 Seeding with srand() #include <time.h> srand(time(0)); srand() sets the starting point (seed) for rand(). time(0) and time(NULL) both give current time in seconds since 1970. Using time as a seed ensures different sequences each run. “By using the current time as a seed, we make the numbers look random every time the program runs.” Random Numbers in a Range To generate a number between min and max: ...

CGPA & Grade Calculator in C

Learn how to build a CGPA & Grade Calculator in C step-by-step. Final code #include<stdio.h> // mark between 0 -100 float cgpa(float mark){ if(mark>100 || mark < 0) return 0; else if(mark >= 80) return 4.0; else if(mark >= 75) return 3.75; else if(mark >= 70) return 3.50; else if(mark >= 65) return 3.25; else if(mark >= 60) return 3.00; else if(mark >= 55) return 2.75; else if(mark >= 50) return 2.50; else if(mark >= 45) return 2.25; else if(mark >= 40) return 2.00; else return 0.0; } // CGPA to grade, where [cgpa] is between 0 - 4.0 char* cgpaToGrade(float cgpa) { if (cgpa > 4.0 || cgpa < 0) return "F"; else if(cgpa >= 4.0) return "A+"; else if(cgpa >= 3.75) return "A"; else if(cgpa >= 3.5) return "A-"; else if(cgpa >= 3.25) return "B+"; else if(cgpa >= 3.0) return "B"; else if(cgpa >= 2.75) return "B-"; else if(cgpa >= 2.5) return "C+"; else if(cgpa >= 2.25) return "C"; else if(cgpa >= 2.0) return "D"; else return "F"; } /// [avg] is the mark between 0 - 100 char* calculateGrade(float avg){ if (avg>100) return "invalid number"; else if(avg >= 80) return "A+"; else if(avg >= 75) return "A"; else if(avg >= 70) return "A-"; else if(avg >= 65) return "B+"; else if(avg >= 60) return "B"; else if(avg >= 55) return "B-"; else if(avg >= 50) return "C+"; else if(avg >= 45) return "C"; else if(avg >= 40) return "D"; else return "F"; } int main(){ int n, total=0; float cgpaTotal=0.0; printf("How many subject you like to calculate: "); scanf("%d", &n); for(int i=0; i< n; i++){ int number ; printf("Enter your %d subject Mark: ", i +1); scanf("%d", &number); cgpaTotal += cgpa(number); total += number; } float avg = total/n; float result = cgpaTotal / n; char* grade = cgpaToGrade(result); printf("total number %d, average %.2f\n", total, avg); printf("Your CGPA %.2f %s\n", result, grade); return 0; }

Quiz Game in C (File-Based)

Build a Quiz Game in C that reads questions from a file! We also learn from hardcoded questions first before moving to file-based input. What You’ll Learn: Reading questions and answers from a file Using arrays and strings to manage data Implementing scoring logic txt file data Our quiz.txt file contains questions in the following format: ...

Student Mark Record Project in C

Build a Student Mark Record Project in C where you can create, show, and remove student records. Learn how to manage data using structs, handle file input/output, and format outputs neatly. Why scanf(" %[^\n]", s.name);? %[^\n] → reads all characters until a newline, including spaces (so you can type full names like “Alice Bob”). ...

BMI calculator

We convert feet & inches to meters, calculate BMI, and show BMI category/status step by step — perfect for beginners learning C programming. Final code #include <stdio.h> /// convert feet and inch to meter float convertFeetInchToMeter(int feet, int inch) { return (feet * .3048) + (inch * .0254); } /// calculate BMI from [weight] in kg and [height] in meter float bmi(float weight, float height) { return weight / (height * height); } /// show message according to [bmi] which is a float void showBMIMessage(float bmi) { if (bmi < 18.5) { printf("status: Underweight\n"); } else if (bmi < 24.9) { printf("status: Normal\n"); } else if (bmi < 29.9) { printf("status: Overweight\n"); } else { printf("status: Obesity\n"); } } int main() { float inch, feet, weight; printf("\nEnter your weight(kg): "); if (scanf("%f", &weight) != 1) { printf("invalid user input, please provide number\n"); return 0; } printf("Enter your height(feet inch): "); if (scanf("%f %f", &feet, &inch) != 1) { printf("invalid user input, please provide number\n"); return 0; } float height = convertFeetInchToMeter(feet, inch); float myBMI = bmi(weight, height); showBMIMessage(myBMI); }

Temperature Converter

How to build a Temperature Converter in C that can convert between Celsius, Fahrenheit, and Kelvin. This beginner-friendly Bangla tutorial explains the logic step by step and includes full coding examples. Final code #include <stdio.h> // show welcome message to choose conversion option void welcome(){ printf("Select conversion:\n"); printf("1. Celsius to Fahrenheit\n"); printf("2. Fahrenheit to Celsius\n"); printf("3. Celsius to Kelvin\n"); printf("4. Kelvin to Celsius\n"); } int main(){ int selectedOption; float temp; welcome(); printf("Enter your choice:"); scanf("%d", &selectedOption); printf("Enter temperature:"); scanf("%f", &temp); switch (selectedOption) { case 1: printf("Farenheight: %.2f\n", (temp * 9/5) + 32); break; case 2: printf("Celsius: %.2f\n", (temp -32) * 5/9); break; case 3: printf("Kelvin: %.2f\n", temp+ 273.15); break; case 4: if(temp < 0){ printf("Kelvin can not be smaller than 0\n"); }else { printf("Kelvin: %.2f\n", temp - 273.15); } break; default: printf("Invalid choice\n"); } }

Currency Converter

Build a Currency Converter in C that can convert between USD, BDT, Gold value, and more! This Bangla tutorial explains the logic step-by-step, shows the full code, and includes a recap to help beginners understand everything clearly. Final code #include <stdio.h> /// show gold price on each currency void calculateGoldPrice(float gram) { double rateBDT = 16028.0; double rateUSD = 131.19; double rateEUR = 113.05; printf("Gold Price for %.5f gram\n", gram); printf("BDT: %.2f\n", gram * rateBDT); printf("USD: %.2f\n", gram * rateUSD); printf("EUR: %.2f\n", gram * rateEUR); } int main(){ int choice; printf("Select conversion:\n"); printf("1. USD to BDT\n"); printf("2. BDT to USD\n"); printf("3. USD to EUR\n"); printf("4. Gold Price\n"); printf("Enter choice: "); scanf("%d", &choice); float amount; printf("Enter amount:"); scanf("%f", &amount); if(amount < 0){ printf("Invalid amount\n"); return 0; } printf("\n"); switch (choice) { case 1: printf("BDT %.2f\n", amount * 120); break; case 2: printf("USD %.2f\n", amount / 120); break; case 3: printf("EUR %.2f\n", amount * .92); break; case 4: calculateGoldPrice(amount); break; default: printf("Invalid input\n"); } return 0; }

Electricity Calculator

How to build a complete Electricity Bill Calculator in C, using a tier-based billing system. In this Bangla tutorial, you’ll understand the logic behind electricity units, slabs, and how to calculate the final bill. Perfect for beginners working on C programming projects! Final code #include <stdio.h> /// calculate bill for a single [tier] float calculateTierBill(float unit, int tierLimit, int rate){ int billedUnit = unit<tierLimit ? unit: tierLimit; return billedUnit * rate; } int main(){ /// bill tiers int tierLimits[] = {50, 75, 100, 200}; int rates[] = {5, 7, 9, 10}; int totalTiers = sizeof(rates) / sizeof(rates[0]); float totalUnits; printf("Enter total used unit: "); if(scanf("%f", &totalUnits)!=1 || totalUnits <0){ printf("Invalid input\n"); return 0; } /// total bill float billed = 0; float remainingUnits = totalUnits; int i=0; while(remainingUnits >0){ float tierBill; if(i< totalTiers){ tierBill = calculateTierBill(remainingUnits, tierLimits[i], rates[i]); float billedUnit = remainingUnits < tierLimits[i]? remainingUnits: tierLimits[i]; remainingUnits -= billedUnit; }else { tierBill = remainingUnits * rates[totalTiers-1]; remainingUnits =0 ; } billed += tierBill; i++; } printf("Billed amount %.2f tk\n", billed); return 0; }