Explanation

hey guys

can someone read this post :

www.cplusplus.com/forum/beginner/268934/

and tell me how he came up with this code ?

1
2
3
4
5
6
7
8
9
10
11
12

#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
   int w1, h1, w2, h2;
   cout << "Input w1 h1 w2 h2: ";   cin >> w1 >> h1 >> w2 >> h2;
   cout << "Number of border squares = " << 2 * ( h1 + h2 + 2 ) + w1 + w2 + abs( w2 - w1 ) << '\n';
}


his code solved my problem but i wanna know
how his code works ? how did he found the formula for my problem ? how did he know where to start or what to do ?

i need someone to explain the math behind the code (someone to explain to me how did he figured out the the answer )

TY IN ADVANCE
Last edited on
Please, keep the discussion in one thread. Douple-posting is not productive.
Topic archived. No new replies allowed.