C++ Online Compiler
Example: C++ program to find the area of a triangle if base and height are given
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// C++ program to find the area of a triangle if base and height are given #include <iostream> using namespace std; int main() { float b, h, a; // b = base // h = height // a = area cout << "Enter the base & height of the triangle::\n"; cin >> b >> h; // Calculate area of the triangle a = (float)((b * h) / 2); // Output cout << "\nArea of the triangle = " << a << " sq. units"; return 0; }
5 7
Output
Clear
ADVERTISEMENTS