Program To Check The Congruency Of Two Triangles In C++ - C++ Programming Tutorial
C++ Course / C++ Programs / Program To Check The Congruency Of Two Triangles In C++

Program To Check The Congruency Of Two Triangles In C++

BLUF: Mastering Program To Check The Congruency Of Two Triangles In C++ is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: Program To Check The Congruency Of Two Triangles In C++

C++ is renowned for its efficiency. Learn how Program To Check The Congruency Of Two Triangles In C++ enables low-level control and high-performance computing in the tutorial below.

The below C++ program checks the congruence of two triangles by the SSS method. Two triangles are said to be congruent if exactly corresponding three sides are equal. After accepting input for the two triangles, it compares the lengths of their sides. If all three sides of the two triangles match, they are considered congruent; otherwise, they are not. This simple method makes checking triangle congruence quick and simple. Additional conditions like SAS, ASA, or AAS can be evaluated by expanding the program to perform a more comprehensive congruency check. It explains the triangular aspects of computational geometry in a fundamental way.

  • SSS (Side-Side-Side): All three of one triangle's sides are equal to the corresponding sides of the other triangle.
  • SAS (Side-Angle-Side): Two sides and the angle between them in one triangle are equal to two sides and the angle between them in the other triangle.
  • ASA (Angle-Side-Angle): Two angles and the side between them in one triangle are equal to the corresponding angles and side in the other triangle.
  • AAS (Angle-Angle-Side): Two angles and the side that is not between them in one triangle are equal to the corresponding angles and side in the other triangle.
  • Congruent triangles:

  • A set of triangles is said to be congruent if all their corresponding sides are equal, if two sides and an angle are equal, if two angles and a side are equal, if two angles and other corresponding sides are equal, or if the hypotenuse and one side are equal.
  • Two triangles are said to be congruent if all of their sides are equivalent to those of another triangle, according to the Side-Side-Side (SSS) congruency criterion. If AB = A'B', BC = B'C', and CA = C'A', triangles are congruent in the triangle ABC and A'B'C' above.
  • Side-Angle-Side (SAS) compared criteria: When two triangles have equal sides and angles, they are said to be congruent according to the Side-Angle-Side (SAS) property. If the triangle above's ABC=A'B' and BC=B'C' are congruent
  • (ASA) Angle-Side-Angle Congruent standards: Two triangles are congruent if their adjacent side lengths and two angles are the same, according to the Angle-Side-Angle (ASA) property. The triangles ABC, A'B'C', and BC=B'C' above are congruent.
  • Angle-Angle-Side (AAS) Congruent Criteria: Two triangles are said to be congruent if their angles and other side lengths are the same. Triangles are congruent; in the triangle above, ABC, A'B'C', and CA=C'A'.
  • Example:

Let's consider an example to verify the similarity of two triangles in C++.

Example

#include <iostream>
using namespace std;

// Function to check SSS congruency (Side-Side-Side)
bool checkSSS(double a1, double b1, double c1, double a2, double b2, double c2) {
    return (a1 == a2 && b1 == b2 && c1 == c2);
}

// Function to check SAS congruency (Side-Angle-Side)
bool checkSAS(double a1, double b1, double A1, double a2, double b2, double A2) {
    return (a1 == a2 && b1 == b2 && A1 == A2);
}

// Function to check ASA congruency (Angle-Side-Angle)
bool checkASA(double A1, double S1, double B1, double A2, double S2, double B2) {
    return (A1 == A2 && S1 == S2 && B1 == B2);
}

int main() {
    double a1, b1, c1, A1, B1, a2, b2, c2, A2, B2;

    cout << "Enter sides of the first triangle (a b c): ";
    cin >> a1 >> b1 >> c1;
    cout << "Enter angles of the first triangle (A B): ";
    cin >> A1 >> B1;

    cout << "Enter sides of the second triangle (a b c): ";
    cin >> a2 >> b2 >> c2;
    cout << "Enter angles of the second triangle (A B): ";
    cin >> A2 >> B2;

    // Checking for congruency
    if (checkSSS(a1, b1, c1, a2, b2, c2)) {
        cout << "Triangles are congruent by SSS rule.\n";
    } else if (checkSAS(a1, b1, A1, a2, b2, A2)) {
        cout << "Triangles are congruent by SAS rule.\n";
    } else if (checkASA(A1, b1, B1, A2, b2, B2)) {
        cout << "Triangles are congruent by ASA rule.\n";
    } else {
        cout << "Triangles are not congruent.\n";
    }

    return 0;
}

Output:

Output

Enter sides of the first triangle (a b c): 5 6 8
Enter angles of the first triangle (A B): 50 60
Enter sides of the second triangle (a b c): 5 6 10
Enter angles of the second triangle (A B): 50 60
Triangles are congruent by SAS rule.
=======================================
Enter sides of the first triangle (a b c): 1 2 3
Enter angles of the first triangle (A B): 35 45
Enter sides of the second triangle (a b c): 3 4 5
Enter angles of the second triangle (A B): 45 60
Triangles are not congruent.

Explanation:

The software receives the dimensions of the sides and angles for two triangles, then examines their congruency based on the SSS, SAS, and ASA criteria, displaying the outcomes. SSS (Side-Side-Side) confirms if all three sides are identical; SAS (Side-Angle-Side) confirms if two sides and the enclosed angle are matching; ASA (Angle-Side-Angle) confirms if two angles and the shared side are matching.

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience