Detailed Print – CSKC
Sign In

Search

siteicon
Code Learning#CPP#7585 Back

Building Simple Formulas

Source Code

		 

Click to open popup
  Related ( ? ) : 2336

Run Output

Give base and height :10.4 3.5
The Area of a triangle with base =10.4 height =3.5 is =18.2

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.