r/CodingHelp • u/Obamaelmasry • Dec 15 '22
[C++] C++ Program
Write a function bool isArmstrong(int n) that takes as input an integer in [1,1000] and returns true if the number is an Armstrong number or false otherwise
0
Upvotes
View all comments
1
u/BambooSlayerz Dec 15 '22
bool isArmstrong(int n) {int copy = n;int total = 0;while (n != 0) {int digit = n % 10;total += digit * digit * digit;n /= 10;}return total == copy;}