Area and Perimeter of Rectangle

Program to calculate area and perimeter of a rectangle

BeginnerTopic: Basic Programs
Back

C++ Area and Perimeter of Rectangle Program

This program helps you to learn the fundamental structure and syntax of C++ programming.

Try This Code
#include <iostream>
using namespace std;

int main() {
    float length, width, area, perimeter;
    
    cout << "Enter length of rectangle: ";
    cin >> length;
    
    cout << "Enter width of rectangle: ";
    cin >> width;
    
    area = length * width;
    perimeter = 2 * (length + width);
    
    cout << "Area of rectangle = " << area << " square units" << endl;
    cout << "Perimeter of rectangle = " << perimeter << " units" << endl;
    
    return 0;
}
Output
Enter length of rectangle: 5
Enter width of rectangle: 3
Area of rectangle = 15 square units
Perimeter of rectangle = 16 units

Understanding Area and Perimeter of Rectangle

This program calculates geometric properties of a rectangle. Area is calculated as length × width, and perimeter is calculated as 2 × (length + width). We use float data type to handle decimal inputs.

Note: To write and run C++ programs, you need to set up the local environment on your computer. Refer to the complete article Setting up C++ Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your C++ programs.

Table of Contents