Day 1: Arithmetic Operators Solution

Task

Write two function for the following instructions:

getArea(length, width): Calculate and return the area of a rectangle having sides length and width.

getPerimeter(length, width): Calculate and return the perimeter of a rectangle ha…


This content originally appeared on DEV Community and was authored by Mohammad Hafijul Islam

Task

Write two function for the following instructions:

  1. getArea(length, width): Calculate and return the area of a rectangle having sides length and width.
  2. getPerimeter(length, width): Calculate and return the perimeter of a rectangle having sides length and width.

The values returned by these functions are printed to stdout by locked stub code in the editor.

Constraints

  • 1 ≤ length, width ≤ 1000
  • length and width are scaled to at most three decimal places.

Input Format

getArea(length, width):

Data Type Parameter Description
Number length A number denoting the length of rectangle.
Number width A number denoting the width of rectangle.

getPerimeter(length, width):

Data Type Parameter Description
Number length A number denoting the length of rectangle.
Number width A number denoting the width of rectangle.

Output Format

Function Return Type Description
getArea(length, width) Number The area of a rectangle having sides length and width.
getPerimeter(length, width) Number The perimeter of a rectangle having sides length and width.

Sample

Input

3
4.5

Output

13.5
15

Explanation

  1. The area of the rectangle is length x width = 3 x 4.5 = 13.5.
  2. The perimeter of the rectangle is 2 x (length + width) = 2 x (3 + 4.5) = 15.

Solution

Arithmetic Operators

Connect

LinkedIn | GitHub


This content originally appeared on DEV Community and was authored by Mohammad Hafijul Islam


Print Share Comment Cite Upload Translate Updates
APA

Mohammad Hafijul Islam | Sciencx (2024-08-03T08:02:14+00:00) Day 1: Arithmetic Operators Solution. Retrieved from https://www.scien.cx/2024/08/03/day-1-arithmetic-operators-solution/

MLA
" » Day 1: Arithmetic Operators Solution." Mohammad Hafijul Islam | Sciencx - Saturday August 3, 2024, https://www.scien.cx/2024/08/03/day-1-arithmetic-operators-solution/
HARVARD
Mohammad Hafijul Islam | Sciencx Saturday August 3, 2024 » Day 1: Arithmetic Operators Solution., viewed ,<https://www.scien.cx/2024/08/03/day-1-arithmetic-operators-solution/>
VANCOUVER
Mohammad Hafijul Islam | Sciencx - » Day 1: Arithmetic Operators Solution. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/08/03/day-1-arithmetic-operators-solution/
CHICAGO
" » Day 1: Arithmetic Operators Solution." Mohammad Hafijul Islam | Sciencx - Accessed . https://www.scien.cx/2024/08/03/day-1-arithmetic-operators-solution/
IEEE
" » Day 1: Arithmetic Operators Solution." Mohammad Hafijul Islam | Sciencx [Online]. Available: https://www.scien.cx/2024/08/03/day-1-arithmetic-operators-solution/. [Accessed: ]
rf:citation
» Day 1: Arithmetic Operators Solution | Mohammad Hafijul Islam | Sciencx | https://www.scien.cx/2024/08/03/day-1-arithmetic-operators-solution/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.