To find the surface area of a cone in ruby, we first need to know the radius and height of the cone. We can use the formula:
surface area = πr(r + √(h^2 + r^2))
Where π
is a mathematical constant, r
is the radius of the cone, and h
is the height of the cone.
We can write a ruby function to calculate surface area of cone as follows:
main.rb166 chars6 lines
This function takes two arguments: the radius
and the height
of the cone, and returns the surface area of the cone.
We can call this function and print the result as follows:
main.rb173 chars7 lines
This will output: The surface area of a cone with radius 5 and height 10 is 219.91148575128568
gistlibby LogSnag