X
X
Xen_OS2014-01-27 11:06:40
Pascal
Xen_OS, 2014-01-27 11:06:40

How to solve a problem in Pascal about quadrants?

There is a problem: "A rectangular coordinate system with X and Y axes is set on the plane, which divides the plane into 4 quadrants. Write a program that enters the coordinates of a point (x, y) and tells in which quadrant (quarters) or on which axis the point is located ."
Here’s what I wrote, but I didn’t fully fulfill the condition of the task, and it turned out clumsily in general:

program kvadrant;
var
  x,y:real;
begin
  writeln('Введите координаты x и y'); readln(x,y);
  if (x>0) and (y>0) then writeln('1й квадрант')
    else if (x<0) and(y>0) then writeln('2й квадрант')
      else if (x<0) and (y<0) then writeln('3й квадрант')
  else writeln('4й квадрант');
end.

I think, here through case it is necessary to do? Or how?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2014-01-27
@omun

Switch case can, of course, be tied, but it will not look so hot. Instead of a standard - true, instead of values ​​- the required logical expressions.
I would suggest recombining the conditions - why compare twice that x>0 or y>0, if it can be done once

A
avalak, 2014-01-27
@avalak

tuts

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question