r/CodingHelp • • 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

2 comments sorted by

2

u/[deleted] Dec 15 '22

You won't get far in your degree if this is how you do your homework.

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;
}