fork download
  1. -module(prog).
  2. -export([main/0]).
  3.  
  4. main() ->
  5. Arr = [1235, 111, 63433, 2, 112],
  6. Target = 2,
  7.  
  8. case search(Arr, Target) of
  9. {found, Index} ->
  10. io:format("The element ~p was found at position ~p~n", [Target, Index]);
  11. not_found ->
  12. io:format("The element ~p was not found~p", [Target])
  13. end.
  14.  
  15. search(List, Target) ->
  16. search(List, Target, 1).
  17.  
  18. search([], _,_) -> not_found;
  19. search([Target | _], Target, Index) -> {found, Index};
  20. search([_ | Tail], Target, Index) -> search(Tail, Target, Index + 1).
Success #stdin #stdout 0.15s 21420KB
stdin
Standard input is empty
stdout
The element 2 was found at position 4