Browse | Submit A New Snippet | Create A Package

 

Quadratic Formula

Type:
Full Script
Category:
Math Functions
License:
GNU General Public License
Language:
Ruby
 
Description:
A quadratic formula script that gets the inputs of the A, B and C numbers and then finds the roots for those numbers.

If you don't know how the quadratic formula works go to: http://www.purplemath.com/modules/quadform.htm

Versions Of This Snippet::

patrick fitzstephens
Snippet ID Download Version Date Posted Author Delete
2091.0.0.0.0.0.12007-04-10 07:19patrick fitzstephens

Download a raw-text version of this code by clicking on "Download Version"

 


Latest Snippet Version: :1.0.0.0.0.0.1

print "Enter A value: "
d = gets
a = d.to_i
print "Enter B value: "
e = gets
b = e.to_i
print "Enter C value: "
f = gets
c = f.to_i
derivitive = b*b - 4*a*c
step1 = b*b + Math.sqrt(derivitive)
step2 = b*b - Math.sqrt(derivitive)
step3 = step1 / 2*a
step4 = step2 / 2*a
if derivitive == 0
print "Number of Roots: 1\nRoot: #{step3}"
elsif derivitive > 0
print "Number of Roots: 2\nRoot 1: #{step3} Root 2 #{step4}"
else
print "No roots"
end
		

Submit a new version

You can submit a new version of this snippet if you have modified it and you feel it is appropriate to share with others..