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}.
 

posted on 2009-08-07 10:35  Quon Lu  阅读(133)  评论(0编辑  收藏  举报

导航