Index
Introduction – Calculator
Here are we are going to create an Calculator which we can use for Find Area of Circle, Area of Square, and Area of Rectangle. This is Basic Level Project for every C Language Developer.
Constants
Here we used constant “PI” which is used for defined the value of Ï€.
Functions
Here we used three different Functions for Creating a different Formula for Calculation, here is it
calculateCircleArea()
: This function calculates and prints the area of a circle. It prompts the user to enter the radius and uses the formula,
- calculateRectangleArea(): This function calculates and prints the area of a rectangle. It prompts the user to enter the length and width, and uses the formula,
- calculateSquareArea() : This function calculates and prints the area of a square. It prompts the user to enter the side length and uses the formula,
C Language Mega Bundle
Output – Calculator
Output of the Project,
Area Calculator
1. Circle
2. Square
3. Rectangle
4. Exit
Choose a shape to calculate the area (1-4): 1
Enter the radius of the circle: 78
The area of the circle is: 19113.45
Project Codes
Here is the Complete Project Codes,
#include <stdio.h> #include <math.h> #define PI 3.14159265358979323846 void calculateCircleArea() { float radius, area; printf("Enter the radius of the circle: "); scanf("%f", &radius); area = PI * radius * radius; printf("The area of the circle is: %.2f\n", area); } void calculateSquareArea() { float side, area; printf("Enter the side length of the square: "); scanf("%f", &side); area = side * side; printf("The area of the square is: %.2f\n", area); } void calculateRectangleArea() { float length, width, area; printf("Enter the length of the rectangle: "); scanf("%f", &length); printf("Enter the width of the rectangle: "); scanf("%f", &width); area = length * width; printf("The area of the rectangle is: %.2f\n", area); } int main() { int choice; while (1) { printf("\nArea Calculator\n"); printf("1. Circle\n"); printf("2. Square\n"); printf("3. Rectangle\n"); printf("4. Exit\n"); printf("Choose a shape to calculate the area (1-4): "); scanf("%d", &choice); switch (choice) { case 1: calculateCircleArea(); break; case 2: calculateSquareArea(); break; case 3: calculateRectangleArea(); break; case 4: printf("Exiting...\n"); return 0; default: printf("Invalid choice. Please choose a valid option (1-4).\n"); } } return 0; }