Calculating the area of geometric shapes is a fundamental concept in mathematics. In this article, we going to write the C program that calculates the area of a square.
Table of Contents
Area of Square Formula
Area = Side*Side
C Program to Calculate Area of Square
Let’s write a simple C program to calculate the area of a square
#include <stdio.h>
void main()
{
float side, area;
printf("Enter the leng of side of square");
scanf("%f", &side);
area = side * side;
printf("Area of square with side length %f =%f", side, area);
}
Output
Explaination of Above C Program
#include <stdio.h>
is a preprocessor that includes a standard input/output library required for input and output operations.- Declare two float variables side and area.
- Ask the user to enter the length of the side of the square using printf() and scanf().
- Calculate the area by using the formula mentioned above and store the result in the area variable.
- At the end print the area by using printf().
2 thoughts on “Area of Square in C”