Rectangle Area C++ HackerRank solution
The mentioned problem is an example of solving real-world maths and implementing it through programming languages. This tutorial will help you with the Rectangle Area C++ HackerRank solution.
Problem statement
In this challenge, you are required to compute the area of a rectangle using classes. The Rectangle class should have two data fields-width and height of int types…
You can check out the complete problem on Rectangle Area (opens in a new tab) at HackerRank.
Also Read: Multi Level Inheritance Hackerrank solution
Solution
Though the problem statement asks to solve it by creating two separate classes, we would be doing it in a straightforward way to help you understand it in a better way. To keep it short, it takes inputs in form of width and height and returns their multiplication as the output.
#include <cmath>
#include <iostream>
using namespace std;
int main() {
int width, height;
cin >> width >> height;
// area(width, height);
cout << width << " " << height << endl << width*height;
return 0;
}