You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: C++/Equilateral_Algorithm.cpp
+31-18Lines changed: 31 additions & 18 deletions
Original file line number
Diff line number
Diff 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
+
1
21
#include<bits/stdc++.h>
2
22
usingnamespacestd;
3
23
24
+
voidarea(double side1){
25
+
cout<<"Area of Equilateral triangle is "<< sqrt(3)/4*side1*side1;
26
+
}
27
+
4
28
intmain() {
5
29
// Initialize variables to store the lengths of the three sides of the triangle
6
30
double side1, side2, side3;
7
-
8
31
// Prompt the user to input the lengths of the three sides
9
32
cout << "Enter the length of side 1: ";
10
33
cin >> side1;
@@ -16,27 +39,17 @@ int main() {
16
39
// Check if all three sides are equal (equilateral)
17
40
if (side1 == side2 && side2 == side3) {
18
41
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
+
19
49
} else {
20
50
cout << "It's not an equilateral triangle." << endl;
21
51
}
22
52
23
53
return0;
24
54
}
25
55
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