' This program uses arrays to display temperature conversion tables
' and temperature as an array subscript to find a given conversion.

DECLARE SUB Main()
DECLARE SUB BuildC(C())
DECLARE SUB BuildF(F())
DECLARE SUB DisplayArray(ArrayName$, Array())
DECLARE SUB FindTemperature(C(), F())
DECLARE FUNCTION Minimum(Value1, Value2)

Main()

SUB Main()
    DIM C(100) AS SINGLE
    DIM F(212) AS SINGLE
    
    BuildC C()
    BuildF F()
    DisplayArray "C", C()
    DisplayArray "F", F()
    FindTemperature C(), F()
END SUB

SUB BuildC(C())
    DIM Index
    
    FOR Index = 0 TO UBOUND(C)
        LET C(Index) = Index * 9 / 5 + 32
    NEXT Index
END SUB

SUB BuildF(F())
    DIM Index
    
    FOR Index = 0 TO UBOUND(F)
        LET F(Index) = (Index - 32) * 5 / 9
    NEXT Index
END SUB

SUB DisplayArray(ArrayName$, Array())
    DIM Index
    
    FOR Index = 0 TO UBOUND(Array)
        PRINT ArrayName$ + "[" + STR$(Index) + "] = " + STR$(Array(Index))
    NEXT Index
END SUB

SUB FindTemperature(C(), F())
    DIM Temp
    DIM Size
    
    LET Size = Minimum(UBOUND(C), UBOUND(F))
    DO
        PRINT "Enter a temperature between 0 and " + STR$(Size)
        INPUT Temp
    LOOP WHILE Temp < 0 OR Temp > Size
    PRINT STR$(Temp) + "° Celsius is " + STR$(C(Temp)) + "° Fahrenheit"
    PRINT STR$(Temp) + "° Fahrenheit is " + STR$(F(Temp)) + "° Celsius"
END SUB

FUNCTION Minimum(Value1, Value2)
    DIM Result
    
    IF Value1 < Value2 THEN
        Result = Value1
    ELSE
        Result = Value2
    END IF
    
    Minimum = Result
END FUNCTION

कोशिश करो

सम्पादन

निम्न कोड मुफ्त ऑनलाइन विकास के वातावरण में से एक में ऊपर कॉपी और पेस्ट करो या अपने खुद के कम्पाइलर/इंटरप्रेटर/आईडीई का उपयोग करें।

यह भी देखें

सम्पादन