program project1;
{$mode objfpc}{$H+}
uses
Sysutils, crt, math;
Var
i,j,ri,rf,si,sf,contador,error:integer; aux1,aux2,p1,p2,p3,q1,q2,q3,area,s,s1,s2,s3,A1,A2,A3,a,b,c,d,e,f,x1,y1,x2,y2,x3,y3:extended;
mensj,m:string;
Begin
Repeat
Repeat
write(' Ingrese la primera coordenada x:');
readln(m);
Val (m,x1,error);
If error<>0 then
writeln(' ERROR DE DATO');
until error=0;
Repeat
write(' Ingrese la primera coordenada y:');
readln(m);
Val (m,y1,error);
If error<>0 then
writeln(' ERROR DE DATO');
until error=0;
Repeat
write(' Ingrese la segunda coordenada x:');
readln(m);
Val(m,x2,error);
If error<>0 then
writeln(' ERROR DE DATO');
until error=0;
Repeat
write(' Ingrese la segunda coordenada y:');
readln(m);
Val (m,y2,error);
if error<>0 then
writeln(' ERROR DE DATO');
until error=0;
Repeat
write(' Ingrese la tercera coordenada x:');
readln(m);
Val (m,x3,error);
If error<>0 then
writeln(' ERROR DE DATO');
until error=0 ;
Repeat
write(' Ingrese la tercera coordenada y:');
readln(m);
Val (m,y3,error);
If error<>0 then
writeln(' ERROR DE DATO');
until error=0;
a:=sqrt(sqr(x2-x1)+sqr(y2-y1));
b:=sqrt(sqr(x3-x2)+sqr(y3-y2));
c:=sqrt(sqr(x1-x3)+sqr(y1-y3));
s:=(a+b+c)/2;
area:= sqrt(s*(s-a)*(s-b)*(s-c));
if (a+b<c) or (a+c<b) or (b+c<a) then
writeln(' Las coordenadas que usted introdujo no pueden formar un triangulo.')
else
begin
P1:=x1;
P2:=x2;
P3:=x3;
q1:=y1;
q2:=y2;
q3:=y3;
if (p3>p1) and (p3>p2) then
begin
if (p2<p1) then
begin
aux1:=p2;
p2:=p1;
p1:=aux1;
end;
end
else
begin
if (p2>p3) and (p3>p1) then
begin
aux1:=p2;
p2:=p3;
p3:=aux1;
end
else
begin
if (p1<p3) and (p3>p2) then
begin
aux1:=p1;
p1:=p3;
p3:=aux1;
end
else
begin
aux1:=p1;
p1:=p3;
p3:=aux1;
if p2<p1 then
begin
aux1:=p2;
p2:=p1;
p1:=aux1;
end;
end;
end;
end;
if (q3>q1) and (q3>q2) then
begin
if (q2<q1) then
begin
aux2:=q2;
q2:=q1;
q1:=aux2;
end;
end
else
begin
if (q2>q3) and (q3>q1) then
begin
aux2:=q2;
q2:=q3;
q3:=aux2;
end
else
begin
if (q1<q3) and (q3>q2) then
begin
aux2:=q1;
q1:=q3;
q3:=aux2;
end
else
begin
aux2:=q1;
q1:=q3;
p3:=aux2;
if q2<q1 then
begin
aux2:=q2;
q2:=q1;
q1:=aux2;
end;
end;
end;
end;
si:=trunc(p1);
sf:=trunc(q1);
ri:=trunc(p3);
rf:=trunc(q3);
contador:=0;
for i:=si to ri do
for j:=sf to rf do
begin
d:=sqrt(sqr(x1-i)+sqr(y1-j));
e:=sqrt(sqr(x2-i)+sqr(y2-j));
f:=sqrt(sqr(x3-i)+sqr(y3-j));
s1:=(a+d+e)/2;
a1:=sqrt(s1*(s1-a)*(s1-d)*(s1-e));
s2:=(b+f+e)/2;
a2:=sqrt(s2*(s2-b)*(s2-f)*(s2-e));
s3:=(d+f+c)/2;
a3:=sqrt(s3*(s3-d)*(s3-f)*(s3-c));
if (abs(area-a1-a2-a3)<=1e-8) and (d<>0) and (e<>0) and (f<>0) then
begin
writeln('(',i,',',j,')');
contador:=contador+1;
end;
end;
writeln (' La cantidad de coordenadas enteras dentro del triangulo es:',contador);
end;
repeat
writeln;
write(' Desea continuar? (S/N):');
readln(mensj);
until (mensj='s') or (mensj='S') or (mensj='n') or (mensj='N');
until (mensj='N') and (mensj='n');
writeln;
writeln;
write(' Presione ENTER para terminar...');
readln;
end.
Comentarios sobre la versión: 1.0 (0)
No hay comentarios