Given four points, the task is to check if the given four points form quadruple in python.
Quadruple:
It is defined as a tuple of integers a, b, c, and d such that a2 + b2 + c2 = d2. They are, in fact, Diophantine Equations solutions. It represents a cuboid with integer side lengths |a|, |b|, and |c| and a space diagonal of |d| in the geometric interpretation.
Condition to check Quadruple = a2 + b2 + c2 = d2
where a, b, c, d are the given four points.
Examples:
Example1:
Input:
Given first point = 6 Given second point = 2 Given third point = 3 Given fourth point = 7
Output:
The given four points { 6 , 2 , 3 , 7 } forms a quadruple
Example2:
Input:
Given first point = 9 Given second point = 2 Given third point = 6 Given fourth point = 11
Output:
The given four points { 9 , 2 , 6 , 11 } forms a quadruple
Program for Pythagorean Quadruple in Python
Below are the ways to check if the given four points form quadruple in python:
Method #1: Using Mathematical Formula (Static Input)
Approach:
- Give the first number as static input and store it in a variable.
- Give the second number as static input and store it in another variable.
- Give the third number as static input and store it in another variable.
- Give the fourth number as static input and store it in another variable.
- Calculate the sum of squares of the given three numbers using the above given mathematical formula and store it in another variable.
- Check if the above result sum is equal to the square of the fourth number using the if conditional statement.
- If it is true, then print “The given four points forms a quadruple”.
- Else print “The given four points do not form a quadruple”.
- The Exit of the Program.
Below is the implementation:
# Give the first number as static input and store it in a variable. p = 6 # Give the second number as static input and store it in another variable. q = 2 # Give the third number as static input and store it in another variable. r = 3 # Give the fourth number as static input and store it in another variable. s = 7 # Calculate the sum of squares of the given three numbers using the above given # mathematical formula and store it in another variable. rslt_sum = p * p + q * q + r * r # Check if the above result sum is equal to the square of the fourth number # using the if conditional statement. if (s * s == rslt_sum): # If it is true, then print "The given four points forms a quadruple". print("The given four points {", p, ",", q, ",", r, ",", s, "} forms a quadruple") # Else print "The given four points do not form a quadruple". else: print("The given four points {", p, ",", q, ",", r, ",", s, "} do not form a quadruple")
# include <iostream> using namespace std int main() { double p = 6 double q = 12 double r = 3 double s = 7 double rslt_sum = p * p + q * q + r * r if ((s * s == rslt_sum)) { cout << "The given four points {" << p << "," << q << "," << r << "," << s << "} forms a quadruple" << endl } else { cout << "The given four points {" << p << "," << q << "," << r << "," << s << "} do not form a quadruple" << endl } }
Output:
The given four points { 6 , 2 , 3 , 7 } forms a quadruple
Method #2: Using Mathematical Formula (User Input)
Approach:
- Give the first number as user input using the int(input()) function and store it in a variable.
- Give the second number as user input using the int(input()) function and store it in another variable.
- Give the third number as user input using the int(input()) function and store it in another variable.
- Give the fourth number as user input using the int(input()) function and store it in another variable.
- Calculate the sum of squares of the given three numbers using the above given mathematical formula and store it in another variable.
- Check if the above result sum is equal to the square of the fourth number using the if conditional statement.
- If it is true, then print “The given four points forms a quadruple”.
- Else print “The given four points do not form a quadruple”.
- The Exit of the Program.
Below is the implementation:
# Give the first number as user input using the int(input()) function and store it in a variable. p = int(input("Enter some random number = ")) # Give the second number as user input using the int(input()) function and store it in another variable. q = int(input("Enter some random number = ")) # Give the third number as user input using the int(input()) function and store it in another variable. r = int(input("Enter some random number = ")) # Give the fourth number as user input using the int(input()) function and store it in another variable. s = int(input("Enter some random number = ")) # Calculate the sum of squares of the given first three numbers using the above given # mathematical formula and store it in another variable. rslt_sum = p * p + q * q + r * r # Check if the above result sum is equal to the square of the fourth number # using the if conditional statement. if (s * s == rslt_sum): # If it is true, then print "The given four points forms a quadruple". print("The given four points {", p, ",", q, ",", r, ",", s, "} forms a quadruple") # Else print "The given four points do not form a quadruple". else: print("The given four points {", p, ",", q, ",", r, ",", s, "} do not form a quadruple")
Output:
Enter some random number = 9 Enter some random number = 2 Enter some random number = 6 Enter some random number = 11 The given four points { 9 , 2 , 6 , 11 } forms a quadruple