Why some of the cases are wrong in my program.
The submission code is #3860389. Please help.
link is:
Cases gone wrong
@Souryaman
Share your code using ide.codingblocks.com so I can have a look. That submission can only be viewed by you.
#include
using namespace std;
int main()
{
int n;
float h,b,p;
cin>>n;
if(n%2==0)
{
p = (n/2)(n/2)- 1;
b = n;
h = (n/2)(n/2) + 1;
cout<<p<<" "<<h<<endl;
}
else if(n%2!=0)
{
p = (n*n)/2.0 - 1/2.0;
b = n;
h = (n*n)/2.0 + 1/2.0;
cout<<p<<" "<<h<<endl;
}
else
{
cout<< "-1";
}
return 0;
}
You are using a wrong approach in your code, you need to take 3 long long int type of variables as a,b and c and then simply check :
if(n%2!=0)
then :
p=(n+1)/2;
q=(n-1)/2;
b=2pq;
c=(pp)+(qq);
cout<<b<<" "<<c;
else
p=n/2;
int q=1;
a=(p+q)*(p-q);
c=(p*p)+(q*q);
cout<<a<<" "<<c;
}
Try use this approach as given in online hint video of the pythagoras triplet.
Since you arent replying to this, I am marking this doubt as resolved, You can reopen it if you face any doubt further…