FastFoodCoding

Login


Connect with one of the following accounts





Login

Please wait while we redirect...

Views: 93   



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

 puts "Enter length of rectangle:"
 rectangleLength = gets.to_f
 puts "Enter width of rectangle:"
 rectangleWidth = gets.to_f
 areaOfRectangle = rectangleLength * rectangleWidth
 puts "Area of rectangle is: #{areaOfRectangle}"
 circumferenceOfRectangle = 2 * (rectangleLength) + 2 * (rectangleWidth)
 puts "Circumference of rectangle is: #{circumferenceOfRectangle}"

Output:

Enter length of rectangle:
50
Enter width of rectangle:
60
Area of rectangle is: 3000.0
Circumference of rectangle is: 220.0



On By


Top Tutorials

Top Questions

Top Articles

Top Blogs

Top News