कंप्यूटर प्रोग्रामिंग/सबरूटीन्स/रूबी

विकिविश्वविद्यालय से

subroutines.rs[सम्पादन | स्रोत सम्पादित करें]

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

def get_f()
    puts "Enter Fahrenheit temperature:"
    f = gets.chomp.to_f
        
    return f
end

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

def display_result(f, c)
    puts (f).to_s + "° Fahrenheit is " + (c).to_s + "° Celsius"
end

def main()
    f = get_f()
    c = calculate_c(f)
    display_result(f, c)
end

main()

कोशिश करो[सम्पादन | स्रोत सम्पादित करें]

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

यह भी देखें[सम्पादन | स्रोत सम्पादित करें]