Possible pairs forming a Pythagorean Triple with a given value | C ++ program to compute all the possible pairs that forms a pythagorean triple with a given value ; Function to generate all possible pairs ; Vector to store all the possible pairs ; Checking all the possible pair in the range of [ 1 , c ) ; If the pair satisfies the condition push it in the vector ; Driver Program ; If no valid pair exist ; Print all valid pairs
#include <bits/stdc++.h> NEW_LINE using namespace std ; vector < pair < int , int > > Pairs ( int C ) { vector < pair < int , int > > ans ; for ( int i = 1 ; i < C ; i ++ ) { for ( int j = i + 1 ; j < C ; j ++ ) { if ( ( i * i ) + ( j * j ) == ( C * C ) ) { ans . push_back ( make_pair ( i , j ) ) ; } } } return ans ; } int main ( ) { int C = 13 ; vector < pair < int , int > > ans = Pairs ( C ) ; if ( ans . size ( ) == 0 ) { cout << " No ▁ valid ▁ pair ▁ exist " << endl ; return 0 ; } for ( auto i = ans . begin ( ) ; i != ans . end ( ) ; i ++ ) { cout << " ( " << i -> first << " , ▁ " << i -> second << " ) " << endl ; } return 0 ; }