หน้าหลัก » ภาษาซีพลัสพลัส (C++) » C++ โค้ดหาพื้นที่สี่เหลี่ยม

C++ โค้ดหาพื้นที่สี่เหลี่ยม




ตัวอย่างการเขียนโค้ดภาษา C++ ในการคำนวณหาพื้นที่สี่เหลี่ยม

ตัวอย่างโค้ด

#include <iostream>

using namespace std;

int main() {
    double width, height, area;

    cout << "Enter the width of the rectangle: ";
    cin >> width;

    cout << "Enter the height of the rectangle: ";
    cin >> height;

    area = width * height;

    cout << "The area of the rectangle is: " << area << endl;

    return 0;
}

แสดงผล

Enter the width of the rectangle: 10
Enter the height of the rectangle: 5
The area of the rectangle is: 50

Enter the width of the rectangle: 100
Enter the height of the rectangle: 100
The area of the rectangle is: 10000