Connect with one of the following accounts


Please wait while we redirect...

Views: 67   

Following program shows you how to calculate square area and circumference.
This program gets square length from user and calculates area and circumference and prints them using following formulas
Area = length X length
Circumference = 4 X length

 puts "Enter length of square:"
 squareLength = gets.to_f
 areaOfSquare = squareLength * squareLength
 puts "Area of square is: #{areaOfSquare}"
 circumferenceOfSquare = 4 * squareLength
 puts "Circumference of square is: #{circumferenceOfSquare}"


Enter length of square:
Area of square is: 25.0
Circumference of square is: 20.0

On By

Top Tutorials

Top Questions

Top Articles

Top Blogs

Top News