# Thread: The sum of squared digits

1. ## The sum of squared digits

I currently want to use the 7 digits: 1234567 to make the sum of squared digits so 1^2+2^2+3^2+4^2+5^2+6^2+7^2=140

I have already done this code as follows:
b = (id/1000000)^2 + ((id%1000000)/100000)^2 +
((id%100000)/10000)^2 + ((id%10000)/1000)^2 +
((id%1000)/100)^2 + ((id%100)/10)^2 + (id%10)^2;

b should equal to 140, but I only get the sum of 2. Can somebody please help me.

2. a^b is not power in C/C++, it's a bitwise operation XOR
bitwise opearation

You should use function pow() declared in cmath header

3. Is this what you mean?
#include <cmath>

I have done this as follows:
b = (id/1000000)pow(1,2) + ((id%1000000)/100000)pow(1,2) + ((id%100000)/10000)pow(1,2) + ((id%10000)/1000)pow(1,2) + ((id%1000)/100)pow(1,2) + ((id%100)/10)pow(1,2) + (id%10)pow(1,2);

I think is wrong, so can you please give me an example. I am new to c++ so I need to look at some example so I can get a better undstanding. Thanx.

4. OI! Ease up on the double posting