+ 1

Why this code gives 153 is Armstrong when run in vs code and gives correct output when run in Sololearn

Why this code gives 153 is Armstrong when run in vs code and gives correct output when run in Sololearn? https://sololearn.com/compiler-playground/cq4XoOXk9HlB/?ref=app

28th Oct 2024, 10:27 AM
Shashikant Pandey
Shashikant Pandey - avatar
7 Answers
0
153 is Armstrong number, as well as 371. for me gives a correct output
28th Oct 2024, 10:58 AM
Mihaly Nyilas
Mihaly Nyilas - avatar
0
Mihaly Nyilas in vs code this code not give correct output
28th Oct 2024, 11:34 AM
Shashikant Pandey
Shashikant Pandey - avatar
0
did you doublecheck the code in vscode? There might be a typographical error. you probably made an error is the "is" and "is not" message... or maybe did not copy the originalNum = num;
28th Oct 2024, 12:30 PM
Bob_Li
Bob_Li - avatar
0
Bob_Li actually I asked chat gpt it says amstrong number convert into float because of pow function then I removed pow and used multiplying 3 times then code excited properly you try with you own vs code same code of me please and tell me
28th Oct 2024, 3:48 PM
Shashikant Pandey
Shashikant Pandey - avatar
0
I guess it depends on your machine and compliler. It didn't give me the wrong answer when I tried it on my laptop. But yes, pow could give you sneaky bugs because of it's implementation. I never realized that. https://stackoverflow.com/questions/59724493/why-cant-i-reproduce-floating-point-issues-with-pow-function https://stackoverflow.com/questions/26860574/pow-implementation-in-cmath-and-efficient-replacement
28th Oct 2024, 4:03 PM
Bob_Li
Bob_Li - avatar
0
Bob_Li am using mingw c++ I don't know but 153 it gives me it's not amstrong when I use pow gpt say it happens because change datatype
28th Oct 2024, 4:53 PM
Shashikant Pandey
Shashikant Pandey - avatar
0
I made a little modification of the code, so it outputs armstrong numbers up to 10000......... https://sololearn.com/compiler-playground/cy7emWL57h3z/?ref=app
28th Oct 2024, 8:45 PM
Jan
Jan - avatar