Law of cosines - triples: Difference between revisions

Added XPL0 example.
m (→‎{{header|R}}: Syntax highlighting.)
(Added XPL0 example.)
Line 2,505:
 
For an angle of 60 degrees there are 18394 solutions.
</pre>
 
=={{header|XPL0}}==
<lang XPL0>proc LawCos(Eqn);
int Eqn;
int Cnt, A, B, C;
 
proc Show;
[Cnt:= Cnt+1;
IntOut(0, A); ChOut(0, ^ );
IntOut(0, B); ChOut(0, ^ );
IntOut(0, C); CrLf(0);
];
 
[Cnt:= 0;
for A:= 1 to 13 do
for B:= 1 to A do
for C:= 1 to 13 do
case Eqn of
1: if A*A + B*B = C*C then Show;
2: if A*A + B*B - A*B = C*C then Show;
3: if A*A + B*B + A*B = C*C then Show
other [];
IntOut(0, Cnt); Text(0, " results^m^j");
];
 
proc ExtraCredit;
int Cnt, A, B, C, C2;
[Cnt:= 0;
for A:= 1 to 10_000 do
for B:= 1 to A-1 do
[C2:= A*A + B*B - A*B;
C:= sqrt(C2);
if C*C = C2 then Cnt:= Cnt+1;
];
Text(0, "Extra credit: ");
IntOut(0, Cnt);
CrLf(0);
];
 
int Case;
[for Case:= 1 to 3 do LawCos(Case);
ExtraCredit;
]</lang>
 
{{out}}
<pre>
4 3 5
8 6 10
12 5 13
3 results
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
8 3 7
8 5 7
8 8 8
9 9 9
10 10 10
11 11 11
12 12 12
13 13 13
15 results
5 3 7
8 7 13
2 results
Extra credit: 18394
</pre>
 
772

edits