Use integer variables and arithmetic to measure a rectangle.
What to build
A program that computes the area and perimeter of a rectangle.
Requirements
- Read the width and the height.
- Print
Area: Aand thenPerimeter: P.
Input
One line: width and height.
Output
Two lines.
Constraints
1 ≤ width, height ≤ 10000.
Example
Input:
3 4
Output:
Area: 12
Perimeter: 14
Why it works
Integer arithmetic gives exact results, and each result goes in its own labelled line.
Examples
Example 1 · Input
3 4
Expected output
Area: 12 Perimeter: 14
Example 2 · Input
10 10
Expected output
Area: 100 Perimeter: 40
Hints
Hint 1
Read both numbers with fscanf(STDIN, "%d %d", $w, $h).
Hint 2
Area is w times h; perimeter is 2 times (w plus h).
Solution
Show one correct solution (try it yourself first)
<?php fscanf(STDIN, "%d %d", $w, $h); echo "Area: ", $w * $h, "\n"; echo "Perimeter: ", 2 * ($w + $h), "\n";