About
This program accepts the side length of a square from the user, calculates the area using the standard formula (Area = side²), and displays the result. It's designed as a beginner-friendly project to demonstrate user input, variables, arithmetic operations, and formatted output in C programming.
Project Structure
- Area_of_a_Square/
- ├── square.c
- └── README.md
Sample Code
#include <stdio.h>
int main() {
float side, area;
printf("Enter the side length of the square: ");
scanf("%f", &side);
area = side * side;
printf("Area of the Square = %.2f", area);
return 0;
}
How to Compile and Run
Using GCC
Compile the program:
gcc square.c -o square
Run the program:
Linux/macOS
./square
Windows
square.exe
Sample Output
Enter the side length of the square: 8
Area of the Square = 64.00
Formula Used
The area of a square is calculated by multiplying the side length by itself.
Requirements
- GCC Compiler or any C Compiler
- Terminal / Command Prompt
- Basic knowledge of C programming
Concepts Used
- Variables and Data Types
- User Input (scanf)
- Output (printf)
- Arithmetic Operations
- Mathematical Formulas
Learning Objectives
By completing this project, you will learn:
- How to accept user input in C
- How to perform calculations using variables
- Working with floating-point values
- Applying geometry formulas in programming
Future Enhancements
- Perimeter of a Square Calculator
- Area Calculator for Multiple Shapes
- Input Validation
- Menu-Driven Geometry Calculator
License
This project is open-source and available under the MIT License.
If you found this project helpful, consider giving it a star on GitHub!