Código de Pascal/Turbo Pascal - Muestra y cantidad de coordenadas enteras dentro de un triangulo

1.0

Actualizado el 26 de Enero del 2017 (Publicado el 28 de Diciembre del 2016)gráfica de visualizaciones de la versión: 1.0
2.198 visualizaciones desde el 28 de Diciembre del 2016
estrellaestrellaestrellaestrellaestrella
estrellaestrellaestrellaestrella
estrellaestrellaestrella
estrellaestrella
estrella

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
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
 

Comentar la versión: 1.0

Nombre
Correo (no se visualiza en la web)
Valoración
Comentarios...
CerrarCerrar
CerrarCerrar
Cerrar

Tienes que ser un usuario registrado para poder insertar imágenes, archivos y/o videos.

Puedes registrarte o validarte desde aquí.

Codigo
Negrita
Subrayado
Tachado
Cursiva
Insertar enlace
Imagen externa
Emoticon
Tabular
Centrar
Titulo
Linea
Disminuir
Aumentar
Vista preliminar
sonreir
dientes
lengua
guiño
enfadado
confundido
llorar
avergonzado
sorprendido
triste
sol
estrella
jarra
camara
taza de cafe
email
beso
bombilla
amor
mal
bien
Es necesario revisar y aceptar las políticas de privacidad

http://lwp-l.com/s3819