How to resolve the algorithm Law of cosines - triples step by step in the Delphi programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Law of cosines - triples step by step in the Delphi programming language

Table of Contents

Problem Statement

The Law of cosines states that for an angle γ, (gamma) of any triangle, if the sides adjacent to the angle are A and B and the side opposite is C; then the lengths of the sides are related by this formula: For an angle of of   90º   this becomes the more familiar "Pythagoras equation": For an angle of   60º   this becomes the less familiar equation: And finally for an angle of   120º   this becomes the equation:

Note: Triangles with the same length sides but different order are to be treated as the same.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Law of cosines - triples step by step in the Delphi programming language

Source code in the delphi programming language

procedure FindTriples(Memo: TMemo; Max,Angle,Coeff: integer);
var Count,A,B,C: integer;
var S: string;
begin
Memo.Lines.Add(Format('Gamma= %d°',[Angle]));
Count:=0;
S:='';
for A:=1 to Max do
 for B:=1 to A do
  for C:=1 to Max do
   if A*A+B*B-Coeff*A*B=C*C then
	begin
	Inc(Count);
	S:=S+Format('(%d,%d,%d) ',[A,B,C]);
	if (Count mod 3)=0 then S:=S+CRLF;
	end;
Memo.Lines.Add(Format('Number of triangles = %d',[Count]));
Memo.Lines.Add(S);
end;



procedure LawOfCosines(Memo: TMemo);
begin
FindTriples(Memo,13,90,0);
FindTriples(Memo,13,60,1);
FindTriples(Memo,13,120,-1);
end;


  

You may also check:How to resolve the algorithm Top rank per group step by step in the R programming language
You may also check:How to resolve the algorithm Literals/Integer step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Determine if a string has all the same characters step by step in the Visual Basic .NET programming language
You may also check:How to resolve the algorithm Identity matrix step by step in the VBA programming language
You may also check:How to resolve the algorithm Terminal control/Hiding the cursor step by step in the FunL programming language