this is my code works properly. is there any other method to do it.
#include
using namespace std;
int profit(int x, int y)
{
int a=x;
int b=y;
int i,ans=0;
int max=0;
for(i=0;i<=(y-x);i++)
{
ans=a^b;
if(max<ans)
max=ans;
a++;
}
for(i=0;i<=(y-x);i++)
{
ans=a^b;
if(max<ans)
max=ans;
b–;
}
return max;
}
int main () {
int x,y,ans;
cin>>x>>y;
ans=profit(x,y);
cout<<ans;
return 0;
}