This is code for pythagoras triplet kindly tell if I missed any corner case .
Not Getting all test cases passed
#include
#include
using namespace std;
double getDiff(double num ){
double ans = num - (int)num;
return ans ;
}
int main(){
int N;
cin>>N;
double m;
double n;
if(N<=1){
cout<<"-1";
return 0 ;
}
// check if N is even
if(N%2 == 0 ){
m= N/2;
n = 1;
}else{
m = (N+1)/2;
n = (N-1)/2;
}
// find the triplet
double least = (pow(m,2)-pow(n,2));
double mid = 2mn;
double greatest = (pow(m,2)+pow(n,2));
// Show only the missing pair
if(least == N){
cout<<mid<<" “<<greatest<<“a”;
}else if(mid == N ){
cout<<least<<” “<<greatest<<“b”;
}
else{
cout<<”-1";
}
}Preformatted text
For input:
23
Your Output:
264 265a
Remove that a from your output.Ensure that your output matches with the sample output given.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.
yes, My earlier code was showing an extra print statement , but after removing it i seem to find some error in my logic . Kindly tell if i have got my corner cases covered . Cant seem to figure out .
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.