I need to print all armstrong numbers ranging from 1 to 10000. My issue is that when my programme runs and hits 150, it does nothing.
as opposed to
As a result, it does not display 153 (an Armstrong number), because the total is 152. I'm not sure whether other numbers are performing the same thing. Yet, as shown here, I checked up to 200 and there is no problem with any other numbers except those in the 150-160 area.
Is this a compiler bug? Is it necessary to reinstall my compiler? I'm currently utilising codeblocks.
Python:
(1^3) + ((6^3)-2) + (0^3)
as opposed to
Python:
(1^3) + (6^3) + (0^3)
As a result, it does not display 153 (an Armstrong number), because the total is 152. I'm not sure whether other numbers are performing the same thing. Yet, as shown here, I checked up to 200 and there is no problem with any other numbers except those in the 150-160 area.
Is this a compiler bug? Is it necessary to reinstall my compiler? I'm currently utilising codeblocks.
Python:
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
for(int i = 0;i <= 1000;++i)
{
int r = i;
int dig = 0;
while(r != 0)
{
dig++;
r /= 10;
}
int n = i, sum = 0;
while(n != 0)
{
int d = n % 10;
sum += pow(d, dig);
n /= 10;
}
if(sum == i)
cout << i << ' ';
}
cout << "\n\n\n";
return 0;
}