I'm implementing the alkhwarizmi algorithm.
It's right but my g++ compiler doesn't like the shift operators: >> and << or I'm doing something wrong.
When I compile it, I get this output:
> g++ -Wall -std=c++0x -o "Al-khwarizmi algorithm.o" "Al-khwarizmi algorithm.cpp" (in directory: /home/akronix/workspace/Algorithms)
> Al-khwarizmi algorithm.cpp: In function ‘int alkhwarizmi(int, int)’: Al-khwarizmi algorithm.cpp:31:9: warning: statement has no effect
> [-Wunused-value] Al-khwarizmi algorithm.cpp:34:9: warning: statement
> has no effect [-Wunused-value] Compilation finished successfully.
Here is my code:
int alkhwarizmi(int x, int y)
{
int sum = 0;
while (x>0)
{
if (x%2)
sum+=y;
//y *= 2;
y << 1;
cout << y <<endl;
//x /= 2;
x >> 1;
cout << x <<endl;
}
return sum;
}
if I use the commented statements (straightforward multiplication and division), everything works fine.
y << 1;
should be
y <<= 1; //^^equals y = y << 1;
Same issue on the statement below:
x >>1; //^^same issue should be x >>= 1;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With