# Pythagorean Triples in C

## Pythagorean Triples in C

A Pythagorean triple consists of three positive integers a, b, and c, such that a² + b² = c². Such a triple is commonly written, and a well-known example is. If is a Pythagorean triple, then so is for any positive integer k. A primitive Pythagorean triple is one in which a, b and c are co-prime.
In this page we will look into a program in C programming language to find Pythagorean Triples from an array

### Problem Statement

Write a program in C programming language where you need to find the pythagorean triples from this list of array

Input Format
-First line will contain the number of elements present in the array.
-Second line will contain the elements of array

Output Format

-Output contains the space separated integers which are pythgorean tripes.

Sample Test Case : 1

Input
6
3 4 6 5 7 8

Output
3 4 5

Sample Test Case : 2

Input
5
10 4 6 12 5

Output
no triples found

### Program for finding pythgorean triples in C

```#include <stdio.h>

int isTriplet(int ar[], int n)
{
int x, y, z;
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
for (int k = j + 1; k < n; k++)
{
// Calculate square of array elements
x = ar[i] * ar[i], y = ar[j] * ar[j], z = ar[k] * ar[k];
if (x == y + z || y == x + z || z == x + y)
{
printf("%d, %d, %d",ar[i],ar[j],ar[k]);
return 1;
}
}
}
}

// If we reach here, no triplet found
return -1;
}

/* Driver program to test above function */
int main()
{
int n;
scanf("%d",&n);
int ar[n];
for(int i=0; i<n; i++)
{
scanf("%d",&ar[i]);
}
int result = isTriplet(ar, n);
if(result == -1)
{
printf("no triples found");
}
return 0;
} ```

## Learn About Arrays in C

Click on the below button to learn about in C Programming Language

Learn Arrays in C

## Learn Data Structures

Click on the below button to study more Data Structure

Learn Data Structures