From 4f52ca1582060205e39391c111fa72a559a37be7 Mon Sep 17 00:00:00 2001 From: Asbar <106991686+AsbarK@users.noreply.github.com> Date: Wed, 11 Oct 2023 11:45:32 +0530 Subject: [PATCH] added cpp program --- Coding/Area of triangle.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Coding/Area of triangle.cpp diff --git a/Coding/Area of triangle.cpp b/Coding/Area of triangle.cpp new file mode 100644 index 00000000..fa962678 --- /dev/null +++ b/Coding/Area of triangle.cpp @@ -0,0 +1,22 @@ +#include + +using namespace std; + +int main() { + double base, height, area; + + cout << "Enter the length of the base of the triangle: "; + cin >> base; + + cout << "Enter the height of the triangle: "; + cin >> height; + + if (base < 0 || height < 0) { + cout << "Invalid input. Base and height cannot be negative." << endl; + } else { + area = 0.5 * base * height; + cout << "The area of the triangle with base " << base << " and height " << height << " is: " << area << endl; + } + + return 0; +}