Menu Close

Create a programming snippet to find the Pythagorean triplet…[Cprogm] FTC

Fazil the tutor of the skill training institute gave  an array of integers to one of highly attentive student of his class Rohan and asked him create a programming snippet to find the Pythagorean triplet that satisfies
a2 + b2 = c2.

Rohan is trying hard to impress his tutor Fazil but he is finding it difficult to complete the task.

Can you help Rohan in completing the task?

Input:
The first line contains T, denoting the number of testcases. Then follows description of testcases. 

Each case begins with a single positive integer N denoting the size of array. 

The second line contains the N space separated positive integers denoting the elements of array A.


Output:
For each testcase, print "Yes" it is Pythagorean Triplet and "No" if not.

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int a[10000000];
int b[10000000];
extern int Triplet(int ar[],int n);
int main(){
  int t;
  scanf("%%d",&t);
  while(t--){
    int n;
    scanf("%%d",&n);
    for(int i=0;i<n;i++){
    scanf("%%d",&a[i]);
    a[i]=a[i]*a[i];
    }
    Triplet(a,n);
  }
return 0;
}
int Triplet(int ar[],int n)
{
  int k=0,i,j,flag=0;
  for(i=0;i<n-1;i++){
  for( j =i+1;j<n;j++){
  b[k]=a[i]+a[j];
  k++;}
  }
  for(i=0;i<n;i++){
  int x=0;
  for(x=0;x<=k;x++){
  if(a[i]==b[x]){
  printf("Yes\n");
  flag=1;
  break;}
  }
  }
  if(flag==0){
  printf("No\n");}
}


INPUT_1:
3
5
85  64  132  189  157
6
87  35  6  10  4  12
7
96  110  247  94  15  9  265

OUTPUT:
Yes
No
Yes


INPUT_2:
4
4
25  3  9  13
8
104  129  451  153  103  185  181  341
6
161  124  139  240  112  289
5
117  55  16  33  130

OUTPUT:
No
Yes
Yes
No


ILLUSTRATION

Executed using gcc

Leave a Reply

Your email address will not be published. Required fields are marked *