Heronian triangles: Difference between revisions
Content added Content deleted
m (→{{header|FutureBasic}}: Remove unsupported 'ConsoleWindow') |
(Added XPL0 example.) |
||
Line 5,258: | Line 5,258: | ||
7 x 65 x 68 210 140 68 |
7 x 65 x 68 210 140 68 |
||
3 x 148 x 149 210 300 149 |
3 x 148 x 149 210 300 149 |
||
</pre> |
|||
=={{header|XPL0}}== |
|||
<syntaxhighlight lang "XPL0">include xpllib; \for Min, GCD, StrSort, StrNCmp, and Print |
|||
func Hero(A, B, C); \Return area squared of triangle with sides A, B, C |
|||
int A, B, C, S; |
|||
[S:= (A+B+C)/2; |
|||
if rem(0) = 1 then return 0; \return 0 if area is not an integer |
|||
return S*(S-A)*(S-B)*(S-C); |
|||
]; |
|||
func Heronian(A, B, C); \Return area of triangle if sides and area are integers |
|||
int A, B, C, Area2, Area; |
|||
[Area2:= Hero(A, B, C); |
|||
Area:= sqrt(Area2); |
|||
return if Area*Area = Area2 then Area else 0; |
|||
]; |
|||
def MaxSide = 200; |
|||
int A, B, C, Area, Count, I, J, K; |
|||
char Array(1000, 5*5); |
|||
[Format(5, 0); |
|||
Count:= 0; |
|||
for A:= 1 to MaxSide do |
|||
for B:= A to MaxSide do |
|||
for C:= B to Min(A+B-1, MaxSide) do |
|||
if GCD(GCD(B,C), A) = 1 then |
|||
[Area:= Heronian(A, B, C); |
|||
if Area > 0 then |
|||
[OpenO(8); |
|||
RlOut(8, float(Area)); |
|||
RlOut(8, float(A+B+C)); |
|||
RlOut(8, float(C)); |
|||
RlOut(8, float(B)); |
|||
RlOut(8, float(A)); |
|||
OpenI(8); |
|||
for I:= 0 to 25-1 do Array(Count,I):= ChIn(8); |
|||
Count:= Count+1; |
|||
]; |
|||
]; |
|||
Print("Count = %d\n", Count); |
|||
StrSort(Array, Count); |
|||
Print(" A B C Perim Area\n"); |
|||
for I:= 0 to 10-1 do |
|||
[for J:= 4 downto 0 do |
|||
Print("%5.5s", @Array(I, J*5+K)); |
|||
Print("\n"); |
|||
]; |
|||
Print("\n"); |
|||
for I:= 0 to Count-1 do |
|||
if StrNCmp(" 210", @Array(I,0), 5) = 0 then |
|||
[for J:= 4 downto 0 do |
|||
Print("%5.5s", @Array(I, J*5+K)); |
|||
Print("\n"); |
|||
]; |
|||
]</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
Count = 517 |
|||
A B C Perim Area |
|||
3 4 5 12 6 |
|||
5 5 6 16 12 |
|||
5 5 8 18 12 |
|||
4 13 15 32 24 |
|||
5 12 13 30 30 |
|||
9 10 17 36 36 |
|||
3 25 26 54 36 |
|||
7 15 20 42 42 |
|||
10 13 13 36 60 |
|||
8 15 17 40 60 |
|||
17 25 28 70 210 |
|||
20 21 29 70 210 |
|||
12 35 37 84 210 |
|||
17 28 39 84 210 |
|||
7 65 68 140 210 |
|||
3 148 149 300 210 |
|||
</pre> |
</pre> |
||