number as square of two integers Get link Facebook X Pinterest Email Other Apps By Admin - May 26, 2011 Given an integer n decide if it is possible to represent it as a sum of two squares of integers. Get link Facebook X Pinterest Email Other Apps Comments AdminMay 27, 2011 at 2:04 PMcin>>X; i=sqrt(X); j=sqrt(X-i*i); while(i>=0 && i>=j) { if((i*i)+(j*j)==X) {count = 1;break;} i--; j=sqrt(X-i*i); } if(count == 1) cout<<"Yes"; else cout<<"No";ReplyDeleteRepliesReplyAdd commentLoad more... Post a Comment
cin>>X;
ReplyDeletei=sqrt(X);
j=sqrt(X-i*i);
while(i>=0 && i>=j)
{
if((i*i)+(j*j)==X)
{count = 1;break;}
i--;
j=sqrt(X-i*i);
}
if(count == 1)
cout<<"Yes";
else cout<<"No";