How to resolve the algorithm Middle three digits step by step in the ERRE programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Middle three digits step by step in the ERRE programming language

Table of Contents

Problem Statement

Write a function/procedure/subroutine that is called with an integer value and returns the middle three digits of the integer if possible or a clear indication of an error if this is not possible. Note: The order of the middle digits should be preserved. Your function should be tested with the following values; the first line should return valid answers, those of the second line should return clear indications of an error: Show your output on this page.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Middle three digits step by step in the ERRE programming language

Source code in the erre programming language

PROGRAM MIDDLE

!$DOUBLE

FUNCTION LUNG(N)
   LUNG=LEN(STR$(INT(ABS(N))))+1
END FUNCTION

FUNCTION NCNT(N)
    NCNT=VAL(MID$(STR$(INT(ABS(N))),(LUNG(N)-1)/2,3))
END FUNCTION

FUNCTION EVEN(N)
    EVEN=INT(N/2)=N/2
END FUNCTION

PROCEDURE NUMBER_EXAM(N->R$)
    R$=""   LG%=LUNG(N)-2
    IF EVEN(LG%) THEN R$="?EVEN,"  END IF
    IF LG%<3 THEN
             R$=R$+"ONLY"+STR$(LG%)+" DIGIT"
             IF LG%=1 THEN
                 R$=R$+"S"
             END IF
    END IF
    IF RIGHT$(R$,1)="," THEN R$=LEFT$(R$,LEN(R$)-1)   EXIT PROCEDURE END IF
    IF LEFT$(R$,1)="?" THEN EXIT PROCEDURE END IF
    IF R$<>"" THEN R$="?"+R$   EXIT PROCEDURE END IF
    R$=STR$(NCNT(N))
    IF LEFT$(R$,1)=" " THEN R$=MID$(R$,2) END IF
    IF LEN(R$)=1 THEN R$="00"+R$  END IF
    IF LEN(R$)=2 THEN R$="0"+R$   END IF
END PROCEDURE

BEGIN
    DATA(123,12345,1234567,987654321,10001,-10001,-123,-100,100,-12345)
    DATA(1,2,-1,-10,2002,-2002,0)
    FOR I%=1 TO 17 DO
        READ(N)
        PRINT(N;"  ",)
        NUMBER_EXAM(N->R$)
        PRINT(R$)
    END FOR
END PROGRAM

  

You may also check:How to resolve the algorithm MD5/Implementation step by step in the Lua programming language
You may also check:How to resolve the algorithm Find limit of recursion step by step in the DWScript programming language
You may also check:How to resolve the algorithm Speech synthesis step by step in the PHP programming language
You may also check:How to resolve the algorithm Temperature conversion step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Set, the card game step by step in the Julia programming language