Building Simple Formulas
Source Code
| Related ( ? ) : 2336 |
Run Output
Code Understanding
This program calculates the area of a triangle when the base and height are given by the user.
• #include allows input and output commands.
• using namespace std; lets us use cout and cin without writing std::.
• float base, height; creates two variables to store decimal values.
• cout << “Give base and height :”; asks the user for input. • cin >> base >> height; takes base and height from the user.
• float area = base * height / 2; calculates the area using the formula ½ × base × height.
• cout << “The Area of a triangle…” displays the result.
• return 0; ends the program.
