1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

スパゲッティプログラム

10 input a
20 input b
30 if a < b goto 100
40 c = a -b
50 d = a * c
60 print d
70 goto 200
100 c = b-a
110 d = b * c
120 print d
200 stop

構造化プログラム1

10 input a
20 input b
30 c = | a - b |
40 if a>b then d = a*c
50 else d= b*c
60 printd
70 stop

絶対値の計算を知っていれば引き算を二つ書く必要がない。
出力行も二つ書く必要がなく、一つでいい。

サブルーチン

10 input a
20 input b
30 c = | a - b |
40 push a, b
50 call 100
60 pop d
70 printd
80 stop
100 pop b,a
110 if a>b then d = a*c
120 else d= b*c
130 push d
140 return

言語仕様によって、サブルーチンにすればいいってもんじゃない。

アセンブラ書く予定。

サブルーチン化すればいいのは、関数機能が標準である言語。

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?