subroutines.lua सम्पादन

-- This program asks the user for a Fahrenheit temperature,
-- converts the given temperature to Celsius,
-- and displays the results.

function get_f()
    local f
    
    print("Enter Fahrenheit temperature:")
    f = tonumber(io.read())
        
    return f
end

function calculate_c(f)
    local c
    
    c = (f - 32) * 5 / 9
        
    return c
end

function display_result(f, c)
    print(f .. "° Fahrenheit is " .. c .. "° Celsius")
end

function main()
    local f
    local c
    
    f = get_f()
    c = calculate_c(f)
    display_result(f, c)
end

main()

कोशिश करो सम्पादन

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

यह भी देखें सम्पादन