2

I'm solving a problem where given two coordinates, calculate the area of the rectangle.

I know that the answer is abs(x1-x2)*abs(y1-y2).

But the problem is for an introduction to C++, and we only know variables and arithmetic.

I don't know if is possible or is a problem to see who know if-statements or abs function

Andrew T.
  • 4,701
  • 8
  • 43
  • 62
  • v * ( (v<0) * (-1) + (v>0)); http://stackoverflow.com/a/9772491/1580953 – Jordan Schnur Nov 28 '16 at 04:02
  • do you know std::max and std::min? Because then you could do std::max(x1,x2)-std::min(x1,x2) and similarly for the y's. Even if not you could implement max as (x1 – Jeremy Kahan Nov 28 '16 at 04:23
  • what domain and data type? 2'os complement integer or IEEE float/double or something else? can you use `& | ^` and `(condition)?true:false`? – Spektre Nov 28 '16 at 07:32
  • @Sugar it is not quite a duplicate inasmuch as that is asked about C and this about C++. I noticed that because my max idea is C++ but not C. But it is very true that the ideas there are relevant (and better than mine). – Jeremy Kahan Nov 28 '16 at 12:25
  • @JeremyKahan is there any real difference between C++ and C basic numeric types? It's not really language-specific question. – Sugar Nov 28 '16 at 14:43
  • @Sugar I guess not. And the consensus is with you. – Jeremy Kahan Nov 28 '16 at 15:45
  • No, we only know int long long but i get the answer and i dont need abs thnk you, but we dont know bool types and less bit operators – Hector Ricardez Nov 28 '16 at 21:02

0 Answers0