This is my C code for determining that 153 is equal to the sum of the cubes of each digit. However, why is 1 + 5^3 + 3^3 = 152 and not 153?
#include <stdio.h>
#include <math.h>
int main()
{
int digit, temp, sum = 0, num = 153;
temp = num;
while (num > 0)
{
digit = num % 10;
sum += pow(digit,3);
num /= 10;
}
printf("%d \n", sum);
if (temp == sum)
{
printf("153 is a special number");
}
else
{
printf("153 is not a special number");
}
}
Edit: I'm using CodeBlocks and I get 152, not 153. If I use double sum instead of int sum however, I get the correct answer. But I'm not sure why using double is correct.