Created
May 4, 2020 21:32
-
-
Save TheEndIsNear/e0257975c05cc581cef4de9a0934b318 to your computer and use it in GitHub Desktop.
Solution for the first assignment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(first). | |
-export([double/1,mult/2,area/3,square/1,triple/1]). | |
mult(X,Y) -> | |
X*Y. | |
double(X) -> | |
mult(2,X). | |
triple(X) -> | |
mult(X, 3). | |
square(X) -> | |
mult(X, X). | |
area(A,B,C) -> | |
S = (A+B+C)/2, | |
math:sqrt(S*(S-A)*(S-B)*(S-C)). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(second). | |
-export([hypotenuse/2,perimeter/2,area/2]). | |
% caluculate the hypotenuse of a right-angled triangle | |
% C^2 = A^2 + B^2 | |
hypotenuse(A, B) -> | |
math:sqrt(first:square(A) + first:square(B)). | |
% calculate the perimeter of a right-angled triangle | |
% perimeter = A + B + C (hypotenuse(A,B)) | |
perimeter(A, B) -> | |
A + B + hypotenuse(A, B). | |
% calculate the area of a right-angled triangle | |
% area = 1/2 * (A * B) | |
area(A, B) -> | |
0.5 * (A * B). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great solution.
Tip: you can start your documentation comments with
@doc
to make them visible toedoc
, in case you later want to generate HTML docs automatically