Answer the question
In order to leave comments, you need to log in
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.
Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question