Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Day 1: Arithmetic Operators Solution
Mohammad Hafijul Islam
Mohammad Hafijul Islam

Posted on

     

Day 1: Arithmetic Operators Solution

Task

Write two function for the following instructions:

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

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

Constraints

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

Input Format

getArea(length, width):

Data TypeParameterDescription
NumberlengthA number denoting the length of rectangle.
NumberwidthA number denoting the width of rectangle.

getPerimeter(length, width):

Data TypeParameterDescription
NumberlengthA number denoting the length of rectangle.
NumberwidthA number denoting the width of rectangle.

Output Format

FunctionReturn TypeDescription
getArea(length, width)NumberThe area of a rectangle having sideslength andwidth.
getPerimeter(length, width)NumberThe perimeter of a rectangle having sideslength andwidth.

Sample

Input

34.5
Enter fullscreen modeExit fullscreen mode

Output

13.515
Enter fullscreen modeExit fullscreen mode

Explanation

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

Solution

Arithmetic Operators

Connect

LinkedIn |GitHub

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

I am a Professional Software Engineer.
  • Location
    Dhaka, Bangladesh
  • Education
    M.Sc in CSE @ Institute of Science & Technology, Bangladesh
  • Pronouns
    He/Him
  • Work
    Sr. Software Engineer @ Clavis Fintech Solutions
  • Joined

More fromMohammad Hafijul Islam

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp