A Program to Find the Area of a Square

In this example, we are giving a program to find the area of a square. The rule of finding the area of a square is: A = length * length.


Program to find the area of a square:

  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. int main() {
  5. float l, area;
  6. cout << "Enter the value of length of a side: " << endl;
  7. cin >> l;
  8. area = pow(l,2);
  9. cout << "Area of square: " << area;
  10. return 0;
  11. }

Output:

Enter the value of the length of a side: 3
Area of square: 9.00