Created
May 7, 2020 09:00
-
-
Save 2torus/3d4bc4f111f8de2247459505f0f38ea7 to your computer and use it in GitHub Desktop.
Programming exercise for "FutureLearn/Programming in Earlang"
This file contains hidden or 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, treble/1, square/1,perimeter/3, area/3]). | |
mult(X, Y) -> | |
X * Y. | |
double(X) -> | |
mult(2,X). | |
treble(X) -> | |
mult(3, X). | |
square(X) -> | |
mult(X, X). | |
perimeter(A, B, C) -> | |
A + B + C. | |
area(A,B,C) -> | |
S = perimeter(A, B, C)/2, | |
math:sqrt(S * (S - A) * (S - B) * (S - C)). |
This file contains hidden or 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([hypot/2, perimeter/2, area/2]). | |
hypot(A, B) -> | |
math:sqrt(first:square(A) + first:square(B)). | |
perimeter(A, B) -> | |
C = hypot(A, B), | |
first:perimeter(A, B, C). | |
area(A, B) -> | |
C = hypot(A, B), | |
first:area(A, B, C). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Excellent!