-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path31.cpp
More file actions
29 lines (28 loc) · 868 Bytes
/
31.cpp
File metadata and controls
29 lines (28 loc) · 868 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <cmath>
int main() {
int number, originalNumber, remainder, result = 0;
int n = 0; // Count the number of digits
std::cout << "Enter an integer: ";
std::cin >> number;
originalNumber = number;
// Count the number of digits in the number
while (originalNumber != 0) {
originalNumber /= 10;
++n;
}
originalNumber = number;
// Calculate the sum of digits each raised to the power of n
while (originalNumber != 0) {
remainder = originalNumber % 10;
result += pow(remainder, n);
originalNumber /= 10;
}
// Check if it's an Armstrong number
if (result == number) {
std::cout << number << " is an Armstrong number." << std::endl;
} else {
std::cout << number << " is not an Armstrong number." << std::endl;
}
return 0;
}