A Program to Find the Area of a Rectangle

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


Program to find the area of a rectangle:

  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. int main() {
  5. float w, h, area;
  6. cout << "Enter the value of width and height: " << endl;
  7. cin >> w >> h;
  8. area = w * h;
  9. cout << "Area of rectangle: " << area;
  10. return 0;
  11. }

Output:

Enter the value of width and height: 3, 4
Area of rectangle: 12.00