C++ Program to Enter Length and Breadth of a Rectangle and Find its Area
C++ program to enter length and breadth of a rectangle and find its area.
In this article, you will learn how to write a c++ program to enter length and breadth of a rectangle and find its area.
You should have the knowledge of the following topics in c++ programming to understand this program.
- C++
main()
function - C++
cin
object - C++
cout
object
Standard formula to calculate the area of a rectangle
A = l * w
where
A = area of the rectangle
l = length of the rectangle
w = width of the rectangle
Source Code
// C++ Program to Enter Length and Breadth of a Rectangle and Find its Area
#include <bits/stdc++.h>
using namespace std;
int main() {
float l, w, a;
cout << "Enter the length & width of the rectangle::\n";
cin >> l >> w;
// Calculate area of rectangle
a = l * w;
// It will print the final output
cout << "\nArea of rectangle = " << a << " units";
return 0;
}
Output
Enter the length & width of the rectangle::
5
7
Area of rectangle = 35 units
Explanation
In the given program, we have taken the inputs 5
rectangle's height and 7
rectangle's width the applied the standard formula p = l * w.
Then It returned to the area 35 units
value of the rectangle.
Also, visit these links
C Program to Enter Length and Breadth of a Rectangle and Find its Area
Java Program to Enter Length and Breadth of a Rectangle and Find its Area
Python Program to Enter Length and Breadth of a Rectangle and Find its Area