Rectangle Area C Hackerrank Solution

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.

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


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;

IndGeek provides solutions in the software field, and is a hub for ultimate Tech Knowledge.