Skip to content

Commit 9678ea6

Browse files
committed
updated equilateral_algorithm by adding the area function
1 parent ba7cf5a commit 9678ea6

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

C++/Equilateral_Algorithm.cpp

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,33 @@
1+
// Explanation:
2+
3+
// Include the necessary header file <bit/stdc++.h> to enable input and output operations.
4+
5+
// Create the main function, the entry point of the program.
6+
7+
// Declare three variables (side1, side2, and side3) to store the lengths of the three sides of the triangle.
8+
9+
// Prompt the user to input the lengths of the three sides using cout and cin for each side.
10+
11+
// Check if all three sides are equal. If they are, it's an equilateral triangle because all sides of an equilateral triangle have the same length. We use an if statement to perform this check.
12+
13+
// If all three sides are equal, display "It's an equilateral triangle" using cout. Otherwise, display "It's not an equilateral triangle."
14+
15+
// Also calculating the area of the equilatereal triangle using area function
16+
17+
// Finally, return 0 to indicate successful execution of the program.
18+
19+
// This program calculates whether a triangle is equilateral based on user-provided side lengths. If all three sides are equal, it's an equilateral triangle; otherwise, it's not.
20+
121
#include<bits/stdc++.h>
222
using namespace std;
323

24+
void area(double side1){
25+
cout<<"Area of Equilateral triangle is "<< sqrt(3)/4*side1*side1;
26+
}
27+
428
int main() {
529
// Initialize variables to store the lengths of the three sides of the triangle
630
double side1, side2, side3;
7-
831
// Prompt the user to input the lengths of the three sides
932
cout << "Enter the length of side 1: ";
1033
cin >> side1;
@@ -16,27 +39,17 @@ int main() {
1639
// Check if all three sides are equal (equilateral)
1740
if (side1 == side2 && side2 == side3) {
1841
cout << "It's an equilateral triangle." << endl;
42+
cout<<"Do you also want to know the area of the equilateral triangle:(Y/N)?";
43+
char d;
44+
cin>>d;
45+
if(d=='Y'){
46+
area(side1);
47+
}
48+
1949
} else {
2050
cout << "It's not an equilateral triangle." << endl;
2151
}
2252

2353
return 0;
2454
}
2555

26-
// Explanation:
27-
28-
// Include the necessary header file <iostream> to enable input and output operations.
29-
30-
// Create the main function, the entry point of the program.
31-
32-
// Declare three variables (side1, side2, and side3) to store the lengths of the three sides of the triangle.
33-
34-
// Prompt the user to input the lengths of the three sides using cout and cin for each side.
35-
36-
// Check if all three sides are equal. If they are, it's an equilateral triangle because all sides of an equilateral triangle have the same length. We use an if statement to perform this check.
37-
38-
// If all three sides are equal, display "It's an equilateral triangle" using cout. Otherwise, display "It's not an equilateral triangle."
39-
40-
// Finally, return 0 to indicate successful execution of the program.
41-
42-
// This program calculates whether a triangle is equilateral based on user-provided side lengths. If all three sides are equal, it's an equilateral triangle; otherwise, it's not.

0 commit comments

Comments
 (0)