how to do code of pythagoras triplet??
Pythagoras triplet
You are given a number n in the question. And you have to print its pythagoras triplet. For example, int the sample test case - the input is 3.
And its pythagoras triplet is - 3 4 5 as 25 = 16 + 9.
Try to come up with some approach and tell me if you are able to do so. Otherwise I will help you.
my code is giving desired results but it only passes 1 test case. can you please help me in making it right. below is my code.
#include
#include<math.h>
using namespace std;
int main(){
int n,i,j,k;
cin>>n;
if(n<=(10^9)){
if(n>0){
for(i=1;i<10;i++)
{
j=(nn)+(ii);
k=(pow(j,.5));
if(i==n and k==n and j%k==0){
cout<<-1;
break;
}
else if(j%k==0){
cout<<i<<" "<<k;
break;
}
}
}
else{
for(i=-1;i>-10;i--)
{
j=(n*n)+(i*i);
k=pow(j,.5);
if(i==n and k==(-n) and j%k==0){
cout<<-1;
break;
}
else if(j%k==0){
cout<<i<<" "<<-k;
break;
}
}
}
}
else{
cout<<-1;
}
return 0;
}
Please send your code in an online IDE. Its easier to debug then.