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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#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:
1 2 |
Enter side of square: 2.5 Area of square is: 6.25 |