Erlang Start![2]
练习链接: http://erlang.org/course/exercises.html
题目:
回答:
题目:
3. Write a function mathStuff:perimeter(Form) which computes the perimeter of different forms. Form can be one of:
{square,Side}
{circle,Radius}
{triangle,A,B,C}
回答:
%% Author: Quon
%% Created: 2009-8-7
%%File: mathStuff.erl
-module(mathStuff).
-export([perimeter/1]).
%Ex3
perimeter({square, Side}) ->
{square, Side*4};
perimeter({circle,Radius}) ->
{circle, 2*3.14*Radius};
perimeter({triangle,A,B,C}) ->
{triangle, A+B+C}.
%% Created: 2009-8-7
%%File: mathStuff.erl
-module(mathStuff).
-export([perimeter/1]).
%Ex3
perimeter({square, Side}) ->
{square, Side*4};
perimeter({circle,Radius}) ->
{circle, 2*3.14*Radius};
perimeter({triangle,A,B,C}) ->
{triangle, A+B+C}.