FastFoodCoding

Login


Connect with one of the following accounts





Login

Please wait while we redirect...

Views: 62   



Following program shows you how to calculate rectangle area and circumference.
This program gets rectangle length and width from user and calculates area and circumference and prints them using following formulas
Area = length X width
Circumference = 2 X length + 2 X width

#include <iostream>
#include <math.h>

int main() {
    float rectangleLength;
    float rectangleWidth;

    std::cout << "Enter length of rectangle:";
    std::cin >> rectangleLength;

    std::cout << "Enter width of rectangle:";
    std::cin >> rectangleWidth;

    float areaOfRectangle = rectangleLength * rectangleWidth;

    std::cout << "Area of rectangle is: " << areaOfRectangle << "\n";

    float circumferenceOfRectangle =
        2 * (rectangleLength) + 2 * (rectangleWidth);

    std::cout << "Circumference of rectangle is: " << circumferenceOfRectangle;
}

Output:

Enter length of rectangle: 13
Enter width of rectangle: 19
Area of rectangle is: 247
Circumference of rectangle is: 64



On By


Top Tutorials

Top Questions

Top Articles

Top Blogs

Top News