Find the remaining vertices of a square from two given vertices | C ++ program for the above approach ; Function to find the remaining vertices of a square ; Check if the x - coordinates are equal ; Check if the y - coordinates are equal ; If the the given coordinates forms a diagonal of the square ; Otherwise ; Square does not exist ; Driver Code ; Given two vertices
#include <cstdlib> NEW_LINE #include <iostream> NEW_LINE using namespace std ; void findVertices ( int x1 , int y1 , int x2 , int y2 ) { if ( x1 == x2 ) { cout << ( x1 + y2 - y1 ) << " , ▁ " << y1 << endl ; cout << ( x2 + y2 - y1 ) << " , ▁ " << y2 ; } else if ( y1 == y2 ) { cout << x1 << " , ▁ " << ( y1 + x2 - x1 ) << endl ; cout << x2 << " , ▁ " << ( y2 + x2 - x1 ) ; } else if ( abs ( x2 - x1 ) == abs ( y2 - y1 ) ) { cout << x1 << " , ▁ " << y2 << endl ; cout << x2 << " , ▁ " << y1 ; } else cout << " - 1" ; } int main ( ) { int x1 = 1 , y1 = 2 ; int x2 = 3 , y2 = 4 ; findVertices ( x1 , y1 , x2 , y2 ) ; return 0 ; }