Write a C program to calculate the area of a square
Description: Take the side of a square as input and print its area.
Hint:
- Area of a square = side x side.
C program to calculate the area of a square
#include <stdio.h>
int main(void) {
float side, area;
printf("Enter the side: ");
scanf("%f", &side);
area = side * side;
printf("Area = %.2f\n", area);
return 0;
}
Output:
Output of the above program is
Enter the side: 4.5
Area = 20.25
How it works
- The side is read as a float, so decimal values also work.
- The area is
side * side, and%.2fprints two decimal digits.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |