]]> ]]>

Квадратное уравнение в Smalltalk

Пример для версий gst 3.1
a := (stdin nextLine) asNumber.
(a == 0)
ifTrue: [
    'Not a quadratic equation.' displayNl.
]
ifFalse: [
    b := (stdin nextLine) asNumber.
    c := (stdin nextLine) asNumber.
    d := (b * b) - (4 * a * c).
    (d == 0)
    ifTrue: [
        'x = ' display.
        ((-1)*b/2/a) displayNl.
    ]
    ifFalse: [
        (d > 0) 
        ifTrue: [
            'x1 = ' display.
            ((-1)*b+(d sqrt)/2/a) displayNl.
            'x2 = ' display.
            ((-1)*b-(d sqrt)/2/a) displayNl.
        ]
        ifFalse: [
            'x1 = (' display.
            ((-1)*b/2/a) display.
            ',' display.
            ((d abs sqrt)/2/a) display.
            ')' displayNl.
            'x2 = (' display.
            ((-1)*b/2/a) display.
            ',' display.
            ((-1)*(d abs sqrt)/2/a) display.
            ')' displayNl.
        ].
    ].
].

Комментарии

]]>

blog comments powered by Disqus

]]>

Работа программистам