0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Erlangで素数かどうかをチェックする

Posted at

前回に引き続き、erlangの修行をする。今回は素数チェッカーを作る。

素数チェッカー

- module(primenum).
- export([primenum/1]).

primenum(Num) when Num > 2 ->
  primecheck(2, Num);
primenum(Num) ->
  io:format("Input integer over 2~n").


primecheck(TargetNum, TargetNum) ->
  true;
primecheck(Num, TargetNum) when TargetNum rem Num =:= 0 ->
  false;
primecheck(Num, TargetNum) ->
  primecheck(Num+1, TargetNum).

感想

前回のfizzbuzzの方が難しかった。次からは並列プログラミングに挑戦したい。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?