In this post we are going to write a C program to calculate the “Area of square”.
Formula for calculating “Area of square” is,
Area of a square = side times side (Area = side * side).
Using this formula let’s write the C Program:
#include <stdio.h>
int main(){
//set the float variables
float side, area;
//get the input value
printf("Enter side of square: ");
scanf("%f", &side);
//calculate the area
area = side * side;
//print the output with 2 decimals
printf("Area of square is: %.2f", area);
return (0);
}Output of the above program:
Enter side of square: 2.5 Area of square is: 6.25