Python Armstrong Number print
Python Armstrong Number print
(OP)
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.
CODE --> python
(1^3) + ((6^3)-2) + (0^3)
as opposed to
CODE --> 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.
CODE --> 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; }
RE: Python Armstrong Number print
The power operator in python is not ^ but **:
>>> 1**3 + 5**3 + 3**3
153
The code on the link you provided works well
https://www.scaler.com/topics/armstrong-number-in-...
I tried it
CODE
and got this output:
CODE