Challenge: Rectangle Calculator
Completed
Read the width and height of a rectangle (two whole numbers) and print its area and perimeter.
Input
Two integers on one line: width and height.
Output
Two lines: Area: A and Perimeter: P.
Example
Input
4 3
Output
Area: 12 Perimeter: 14
Editor
C
Hints
Read both numbers with one scanf("%d %d", ...).
Perimeter is 2 * (width + height).
Solution explanation
Area multiplies the sides; the perimeter adds all four sides, which is twice width plus height.
Show solution
#include <stdio.h>
int main() {
int width, height;
scanf("%d %d", &width, &height);
printf("Area: %d\n", width * height);
printf("Perimeter: %d\n", 2 * (width + height));
return 0;
} Output
Answer
You can practice without logging in. Log in to save completion.
Save your progress
You're practising as a guest, so your progress won't be saved.
- Track every lab you complete
- Earn verifiable lab certificates
- See your progress in every module