To check whether the triplet is pythagorean or not




In this we are going to see a program to check whether the triplet is pythagorean or not in C++ Programming Language.



The Code given below can be used in TURBO C++ Compilers: -

#include <iostream.h>
#include <math.h>
#include <stdio.h>
#include <conio.h>


void main()
{
    clrscr();
    int a, b, c, x, y, z;
    cout << "Enter the values of a,b,c:" << endl;
    cout << "a=";
    cin >> a;
    cout << "b=";
    cin >> b;
    cout << "c=";
    cin >> c;
    a = pow(a, 2);
    b = pow(b, 2);
    c = pow(c, 2);
    cout << a << "," << b << "," << c << endl;

    if (a == b + c || b == a + c || c == a + b)
    {
        cout << "It is a Pythagorean Triplet" << endl;
    }

    else
    {
        cout << "It is not a Pythagorean Triplet" << endl;
    }

    getch();
}

The Code given below can be used in gcc/g++ Compilers: -

#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    int a, b, c, x, y, z;
    cout << "Enter the values of a,b,c:" << endl;
    cout << "a=";
    cin >> a;
    cout << "b=";
    cin >> b;
    cout << "c=";
    cin >> c;
    a = pow(a, 2);
    b = pow(b, 2);
    c = pow(c, 2);
    cout << a << "," << b << "," << c << endl;

    if (a == b + c || b == a + c || c == a + b)
    {
        cout << "It is a Pythagorean Triplet" << endl;
    }

    else
    {
        cout << "It is not a Pythagorean Triplet" << endl;
    }

    return 0;
}


#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post