ZyX_I avatar ZyX_I committed f76a98a

Added calculator: for completeness

Comments (0)

Files changed (1)

+      PROGRAM calc
+       INTEGER A, B, I, C, SIGN, OP
+       INTEGER ZERO, NINE, PLUS, MINUS, MULT, DIV, POW
+       CHARACTER INPUT*20
+       PARAMETER (ZERO = ICHAR('0'), NINE  = ICHAR('9'),
+     $            PLUS = ICHAR('+'), MINUS = ICHAR('-'),
+     $            MULT = ICHAR('*'), DIV   = ICHAR('/'),
+     $            POW  = ICHAR('^'))
+       WRITE(*,*)'Enter expression (NUM{operator}NUM):'
+       READ(*,'(A20)')INPUT
+       A = 0
+       B = 0
+       I = 1
+       OP = 0
+       IF(ICHAR(INPUT(I:I)) .EQ. ICHAR('-')) THEN
+        SIGN = -1
+        I = I+1
+       ELSE
+        SIGN = 1
+       END IF
+  100   C = ICHAR(INPUT(I:I))
+        IF(      ZERO .LE. C
+     $     .AND. C    .LE. NINE) THEN
+         A = A*10 + (C-ZERO)
+        ELSE
+         IF (     C .EQ. PLUS
+     $       .OR. C .EQ. MINUS
+     $       .OR. C .EQ. MULT
+     $       .OR. C .EQ. DIV
+     $       .OR. C .EQ. POW) THEN
+          OP = C
+          I = I+1
+          GOTO 200
+         END IF
+        END IF
+        I = I+1
+        IF(I .LE. 20) THEN
+         GOTO 100
+        END IF
+  200  A = A*SIGN
+       IF(ICHAR(INPUT(I:I)) .EQ. ICHAR('-')) THEN
+        SIGN = -1
+        I = I+1
+       ELSE
+        SIGN = 1
+       END IF
+  300   C = ICHAR(INPUT(I:I))
+        IF(      ZERO .LE. C
+     $     .AND. C    .LE. NINE) THEN
+         B = B*10 + (C-ZERO)
+        END IF
+        I = I+1
+        IF(I .LE. 20) THEN
+         GOTO 300
+        END IF
+  400  B = B*SIGN
+       IF(OP .EQ. PLUS) THEN
+        WRITE(*,'(I10)')(A+B)
+       ELSE
+        IF(OP .EQ. MINUS) THEN
+         WRITE(*,'(I10)')(A-B)
+        ELSE
+         IF(OP .EQ. MULT) THEN
+          WRITE(*,'(I10)')(A*B)
+         ELSE
+          IF(OP .EQ. DIV) THEN
+           IF (B .EQ. 0) THEN
+            STOP 'Division by zero is prohibited'
+           END IF
+           WRITE(*,'(F10.5)')(REAL(A)/B)
+          ELSE
+           IF(OP .EQ. POW) THEN
+            WRITE(*,'(I10)')(A**B)
+           END IF
+          END IF
+         END IF
+        END IF
+       END IF
+      END
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.